Compiler bug creating a module with Visual C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Ross

    #1

    Compiler bug creating a module with Visual C++

    I get a link error when I try and create a module of the following
    very simple managed C++ code. I can't imagine a more minimum piece of
    code, so I imagine that this is some sort of compiler bug.

    #using <mscorlib.dll >
    __gc public class Test : public System::Object
    {
    };

    $ cl /clr:noAssembly /LD test.cpp
    Microsoft (R) C/C++ Optimizing Compiler Version 13.10.3077 for .NET
    Framework
    Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

    test.cpp
    Microsoft (R) Incremental Linker Version 7.10.3077
    Copyright (C) Microsoft Corporation. All rights reserved.

    /out:test.dll
    /noentry
    /noassembly
    /dll
    /implib:test.lib
    test.obj
    LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main
    referenced in function _mainCRTStartup
    test.dll : fatal error LNK1120: 1 unresolved externals
  • Girish Bharadwaj

    #2
    Re: Compiler bug creating a module with Visual C++

    That does not look like a bug. Since you are asking it to create a
    executable, it could not find an entry point. If you do the same in C# ..
    using System;
    public class Test {
    }

    and compile this, it will complain about "no entry point".

    This is just complaining in C++ speak. :)


    --
    Girish Bharadwaj
    "Peter Ross" <pro@missioncri ticalit.com> wrote in message
    news:88d535d6.0 310140222.3d7c0 5d2@posting.goo gle.com...[color=blue]
    > I get a link error when I try and create a module of the following
    > very simple managed C++ code. I can't imagine a more minimum piece of
    > code, so I imagine that this is some sort of compiler bug.
    >
    > #using <mscorlib.dll >
    > __gc public class Test : public System::Object
    > {
    > };
    >
    > $ cl /clr:noAssembly /LD test.cpp
    > Microsoft (R) C/C++ Optimizing Compiler Version 13.10.3077 for .NET
    > Framework
    > Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
    >
    > test.cpp
    > Microsoft (R) Incremental Linker Version 7.10.3077
    > Copyright (C) Microsoft Corporation. All rights reserved.
    >
    > /out:test.dll
    > /noentry
    > /noassembly
    > /dll
    > /implib:test.lib
    > test.obj
    > LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main
    > referenced in function _mainCRTStartup
    > test.dll : fatal error LNK1120: 1 unresolved externals[/color]


    Comment

    • Girish Bharadwaj

      #3
      Re: Compiler bug creating a module with Visual C++

      Doh! I did not read the complete message. :) It does not seem to make sense
      since you are passing /noentry.. why is it complaining..
      sorry. ignore my last post.

      --
      Girish Bharadwaj
      "Girish Bharadwaj" <girishb.at.mvp s.dot.org> wrote in message
      news:%23$YeeQlk DHA.2000@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > That does not look like a bug. Since you are asking it to create a
      > executable, it could not find an entry point. If you do the same in C# ..
      > using System;
      > public class Test {
      > }
      >
      > and compile this, it will complain about "no entry point".
      >
      > This is just complaining in C++ speak. :)
      >
      >
      > --
      > Girish Bharadwaj
      > "Peter Ross" <pro@missioncri ticalit.com> wrote in message
      > news:88d535d6.0 310140222.3d7c0 5d2@posting.goo gle.com...[color=green]
      > > I get a link error when I try and create a module of the following
      > > very simple managed C++ code. I can't imagine a more minimum piece of
      > > code, so I imagine that this is some sort of compiler bug.
      > >
      > > #using <mscorlib.dll >
      > > __gc public class Test : public System::Object
      > > {
      > > };
      > >
      > > $ cl /clr:noAssembly /LD test.cpp
      > > Microsoft (R) C/C++ Optimizing Compiler Version 13.10.3077 for .NET
      > > Framework
      > > Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
      > >
      > > test.cpp
      > > Microsoft (R) Incremental Linker Version 7.10.3077
      > > Copyright (C) Microsoft Corporation. All rights reserved.
      > >
      > > /out:test.dll
      > > /noentry
      > > /noassembly
      > > /dll
      > > /implib:test.lib
      > > test.obj
      > > LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main
      > > referenced in function _mainCRTStartup
      > > test.dll : fatal error LNK1120: 1 unresolved externals[/color]
      >
      >[/color]


      Comment

      • Girish Bharadwaj

        #4
        Re: Compiler bug creating a module with Visual C++

        BTW: the same code compiles just fine on a .NET 1.0.

        cl /clr:noAssembly /LD empty.cpp
        Microsoft (R) C/C++ Optimizing Compiler Version 13.00.9466 for .NET
        Framework
        Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.

        empty.cpp
        Microsoft (R) Incremental Linker Version 7.00.9466
        Copyright (C) Microsoft Corporation. All rights reserved.

        /out:empty.dll
        /noentry
        /noassembly
        /dll
        /implib:empty.li b
        empty.obj


        I guess you are right. This probably is something funky with the .NET 1.1 ..

        --
        Girish Bharadwaj
        "Girish Bharadwaj" <girishb.at.mvp s.dot.org> wrote in message
        news:%23$YeeQlk DHA.2000@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > That does not look like a bug. Since you are asking it to create a
        > executable, it could not find an entry point. If you do the same in C# ..
        > using System;
        > public class Test {
        > }
        >
        > and compile this, it will complain about "no entry point".
        >
        > This is just complaining in C++ speak. :)
        >
        >
        > --
        > Girish Bharadwaj
        > "Peter Ross" <pro@missioncri ticalit.com> wrote in message
        > news:88d535d6.0 310140222.3d7c0 5d2@posting.goo gle.com...[color=green]
        > > I get a link error when I try and create a module of the following
        > > very simple managed C++ code. I can't imagine a more minimum piece of
        > > code, so I imagine that this is some sort of compiler bug.
        > >
        > > #using <mscorlib.dll >
        > > __gc public class Test : public System::Object
        > > {
        > > };
        > >
        > > $ cl /clr:noAssembly /LD test.cpp
        > > Microsoft (R) C/C++ Optimizing Compiler Version 13.10.3077 for .NET
        > > Framework
        > > Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
        > >
        > > test.cpp
        > > Microsoft (R) Incremental Linker Version 7.10.3077
        > > Copyright (C) Microsoft Corporation. All rights reserved.
        > >
        > > /out:test.dll
        > > /noentry
        > > /noassembly
        > > /dll
        > > /implib:test.lib
        > > test.obj
        > > LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main
        > > referenced in function _mainCRTStartup
        > > test.dll : fatal error LNK1120: 1 unresolved externals[/color]
        >
        >[/color]


        Comment

        • Tomas Restrepo \(MVP\)

          #5
          Re: Compiler bug creating a module with Visual C++

          Hi Peter,
          [color=blue]
          > I get a link error when I try and create a module of the following
          > very simple managed C++ code. I can't imagine a more minimum piece of
          > code, so I imagine that this is some sort of compiler bug.
          >
          > #using <mscorlib.dll >
          > __gc public class Test : public System::Object
          > {
          > };[/color]

          Not at all. You're running against the changes made to the compiler/linker
          to minimize the Loader-Lock problem (a module is esentially a dll, and will
          be subject to the same problems).

          To get around it, just link with nochkclr.obj:
          cl /clr:noAssembly /LD test.cpp nockclr.obj

          --
          Tomas Restrepo
          tomasr@mvps.org


          Comment

          • Peter Ross

            #6
            Re: Compiler bug creating a module with Visual C++

            "Tomas Restrepo \(MVP\)" <tomasr@mvps.or g> wrote in message news:<#UeFPvnkD HA.3312@tk2msft ngp13.phx.gbl>. ..[color=blue]
            > Hi Peter,
            >[color=green]
            > > I get a link error when I try and create a module of the following
            > > very simple managed C++ code. I can't imagine a more minimum piece of
            > > code, so I imagine that this is some sort of compiler bug.
            > >
            > > #using <mscorlib.dll >
            > > __gc public class Test : public System::Object
            > > {
            > > };[/color]
            >
            > Not at all. You're running against the changes made to the compiler/linker
            > to minimize the Loader-Lock problem (a module is esentially a dll, and will
            > be subject to the same problems).
            >
            > To get around it, just link with nochkclr.obj:
            > cl /clr:noAssembly /LD test.cpp nockclr.obj[/color]

            Thank you Tomas that did solve the problem.

            I had seen some KB articles about the Loader-Lock problem, but
            couldn't relate it directly to my problem.

            Could you point me to a resource which mentions nochkclr.obj? I am
            interested to see why I didn't work it out.

            Regards,
            Peter

            Comment

            • Tomas Restrepo \(MVP\)

              #7
              Re: Compiler bug creating a module with Visual C++

              Hi Peter,
              [color=blue]
              > Thank you Tomas that did solve the problem.
              >
              > I had seen some KB articles about the Loader-Lock problem, but
              > couldn't relate it directly to my problem.[/color]

              It was a logical conclusion for me, since modules are usually linked into an
              assembly, typically a DLL one (and not an EXE).
              [color=blue]
              > Could you point me to a resource which mentions nochkclr.obj? I am
              > interested to see why I didn't work it out.[/color]

              Humm... let me see... I believe the documentation mentions it... See [1] and
              [2]

              [1]
              http://msdn.microsoft.com/library/de...rorlnk2019.asp
              [2]
              http://msdn.microsoft.com/library/en...omixedmode.asp

              --
              Tomas Restrepo
              tomasr@mvps.org


              Comment

              Working...