lnk 2019 error

hey guys,

i was wrapping a native dll inside a managed c++ dll.

i was compiling to test how i was going, and it got a weird lnk error. it is the following:

error lnk2019 : unresolved external symbol _main referenced in function _mainCRTStartup.

so how am i suppose to solve this issue imusing the VS 2003.

thx


Answer this question

lnk 2019 error

  • Oscar Thornell

    i have managed to solve the problem with vs 2005. but its not totally solved Sad

    in vs 2005, i declared a class with __nogc, and clr:oldSyntax and compiled.

    it compiled fine without errors.

    i did a C# app. to test it, and i managed to do an object from that class. but i couldbt see anything in that class, like i cant see variables at all any functions. and it also saw the class i made in managed dll as a struct :S

    why is that

  • TJak

    Which lib or obj are you getting the error in Could you share a code sample that reproduces the error Also, please include the build log.

    You might need to link with the /NOENTRY linker switch. Here is a link that can help: http://support.microsoft.com/ id=814472

    Thanks,
      Ayman Shoukry
      VC++ Team



  • EvilSilver

    I just tried the following small sample and it works as expected:

    Build i.dll (cl /LD /CLR:oldsyntax)
    //i.cpp
    public __gc class x
    {
     public:
     int g;
    };

    Use class x in the C# as follows (after add i.dll to the references):
    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace
    temp
    {
       class Program
       {
          static void Main(string[] args)
          {
             x anything = new x();
             anything.g = 10;
          }
       }
    }

    I was using the beta2 VC2005 build.

    Thanks,
      Ayman Shoukry
      VC++ Team


  • gcy80

    i tried as well wat that link has, but still not working, it brought up, lots of other linking error, most of them were redifning errors.
  • Frogmancomethagain

    <html>
    <head>
    <META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-16">
    </head>
    <body>
    <pre>
    <table width=100% bgcolor=#CFCFE5><tr> <td> <font face=arial size=+3>
    Build Log
    </font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>
    <h3>Build started: Project: MTokamak2005, Configuration: Debug|Win32</h3>
    </pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
    Command Lines
    </font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Creating temporary file "c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\RSP0000593488156.rsp" with contents
    [
    /Od /D &quot;WIN32&quot; /D &quot;_DEBUG&quot; /D &quot;_MBCS&quot; /D &quot;_WINDLL&quot; /FD /EHa /MDd /Yu&quot;stdafx.h&quot; /Fp&quot;Debug\MTokamak2005.pch&quot; /Fo&quot;Debug\\&quot; /Fd&quot;Debug\vc80.pdb&quot; /W3 /c /Zi /clr:oldSyntax /TP /FU &quot;c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.dll&quot; /FU &quot;c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.Data.dll&quot; /FU &quot;c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.XML.dll&quot;

    &quot;.\MTokamak2005.cpp&quot;
    ]
    Creating command line "cl.exe @"c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\RSP0000593488156.rsp" /nologo /errorReport:prompt"
    Creating temporary file "c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\RSP00005A3488156.rsp" with contents
    [
    /OUT:&quot;C:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\Debug\MTokamak2005.dll&quot; /INCREMENTAL /DLL /MANIFEST /MANIFESTFILE:&quot;Debug\MTokamak2005.dll.intermediate.manifest&quot; /DEBUG /ASSEMBLYDEBUG /PDB:&quot;c:\documents and settings\ramy\my documents\visual studio 2005\projects\mtokamak2005\debug\MTokamak2005.pdb&quot; /MACHINE:X86 /FIXED:No /NOENTRY

    &quot;.\debug\MTokamak2005.obj&quot;

    &quot;.\debug\AssemblyInfo.obj&quot;

    &quot;.\debug\Stdafx.obj&quot;

    &quot;.\debug\app.res&quot;
    ]
    Creating command line "link.exe @"c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\RSP00005A3488156.rsp" /NOLOGO /ERRORREPORT:PROMPT"
    Creating temporary file "c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\RSP00005B3488156.rsp" with contents
    [
    /outputresource:&quot;..\debug\MTokamak2005.dll;#2&quot; /manifest

    &quot;.\debug\MTokamak2005.dll.intermediate.manifest&quot;
    ]
    Creating command line "mt.exe @"c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\RSP00005B3488156.rsp" /nologo"
    Creating temporary file "c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\BAT00005C3488156.bat" with contents
    [
    @echo Manifest resource last updated at %TIME% on %DATE% &gt; &quot;.\debug\mt.dep&quot;
    ]
    Creating command line """c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\BAT00005C3488156.bat"""
    </pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
    Output Window
    </font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Compiling...
    MTokamak2005.cpp
    Linking...
    Embedding manifest...
    </pre></table><table width=100% bgcolor=#DFDFE5><tr><td><font face=arial size=+2>
    Results
    </font></table><table width=* cellspacing=0 cellpadding=0><tr><td width=0 bgcolor=#EDEDF5>&nbsp;</td><td width=0 bgcolor=#FFFFFF>&nbsp;</td><td width=*><pre>Build log was saved at "file://c:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\MTokamak2005\Debug\BuildLog.htm"
    MTokamak2005 - 0 error(s), 0 warning(s)
    </pre></table><table   width=100% height=20 bgcolor=#CFCFE5><tr><td><font face=arial size=+2>
    </font></table></body></html>

    and tokamak.lib is a ready made dll, it is a physics engine. if i remember correctly, it is built using VC 6. so its pure native.


  • PMass

    Are you able to see the content of the referenced dll in the class view

    Try reproducing the issue without using the old VC 6.0 lib. that is to say, try to build any (small sample) managed dll and try using it from the C# code and see if it works.

    If you can still reproduce the problem, please post such small sample.

    Thanks,
      Ayman Shoukry
      VC++ Team



  • new2C#

    and the way i experienced until now, in order to load or make an object from native dll in managed C++, u have to put __nogc before the managed class that will wrap the native, right

    but by putting __nogc this also means that the class isnt managed, so C# not seeing its contents might be abit obvious. thats wat im concluding, but not sure how to get arround that.

    if u have any suggestions please do help me

  • Ziva_Y

    yeah that works fine forme too now.

    let me explain wat i experienced by modifing ur code abit.

    it is when i put __nogc instead of __gc in class declaration i dont c the class contents in C#. by following:

    Build i.dll (cl /LD /CLR:oldsyntax)
    //i.cpp
    public __nogc class x
    {
     public:
     int g;
    };

    this is where in C# it sees nothing in class x! even if there was a constructor and it took paramaters, it would not see it in C#.

  • pwelter34

    ok, here is the whole code :d it is kinda small, so dont worry.

    my managed DLL is composed of two file, header and cpp.

    the header has following:

    // MTokamak.h

    #pragma managed

    #pragma once

    #include <tokamak.h>

    #pragma comment(lib, "tokamak.lib")

    using namespace System;

    namespace MTokamak

    {

    public __gc class Sim

    {

    public:

    neSimulator __nogc* m_Simulator;

    neSimulatorSizeInfo *m_SimulatorSizeInfo;

    neV3 *m_vGravity;

    Sim()

    {

    m_SimulatorSizeInfo = new neSimulatorSizeInfo();

    m_SimulatorSizeInfo->rigidBodiesCount = 1;

    m_SimulatorSizeInfo->animatedBodiesCount = 1;

    m_SimulatorSizeInfo->geometriesCount = m_SimulatorSizeInfo->rigidBodiesCount + m_SimulatorSizeInfo->animatedBodiesCount;

    m_SimulatorSizeInfo->overlappedPairsCount = m_SimulatorSizeInfo->geometriesCount * (m_SimulatorSizeInfo->geometriesCount - 1) / 2;
    m_SimulatorSizeInfo->rigidParticleCount = 0;

    m_SimulatorSizeInfo->constraintsCount = 0;

    m_SimulatorSizeInfo->terrainNodesStartCount = 0;

    m_vGravity = new neV3();

    m_vGravity->Set(0.0f, -10.0f, 0.0f);

    m_Simulator = neSimulator::CreateSimulator(*m_SimulatorSizeInfo, NULL, m_vGravity);

    }

    };

    }

    and cpp basically has nothing but worth mentioning:

    // This is the main DLL file.

    #include "stdafx.h"

    #include "MTokamak.h"


    there thats my managed DLL, that im trying to build.

    the native C++ im trying to compile is tokamak.dll, so i included the header and linked the .lib.

    the build log that you requested is this:

    ------ Build started: Project: MTokamak, Configuration: Debug Win32 ------

    Compiling...

    MTokamak.cpp

    Linking...

    LIBC.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup

    C:\Documents and Settings\RamY\My Documents\Visual Studio Projects\MTokamak\Debug\MTokamak.dll : fatal error LNK1120: 1 unresolved externals

    Build log was saved at "file://c:\Documents and Settings\RamY\My Documents\Visual Studio Projects\MTokamak\Debug\BuildLog.htm"

    MTokamak - 2 error(s), 0 warning(s)

     

    ---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped

    so why is it giving me that lnk 2019 error and btw, i did the same code under VS 2005 beta 2, and it gave me another totally different error, it gave me, can not open libc.lib, and when i included that file, it gave me ALOT of error in that .lib.

    so its not working uner 2003 nor 2005, can u advise me please :D

    thats alot.


  • Pacharrin

    Great that you can now use VC2005 with no errors!

    As for the C# issue.
    see http://msdn2.microsoft.com/library/ms173184(en-us,vs.80).aspx.

    If the C# link doesn't help resolving the issue try the C# forums at http://forums.microsoft.com/msdn/default.aspx ForumGroupID=9

    By the way, you can continue using managed C++. Here is a reference that might be useful http://msdn2.microsoft.com/library/x0w2664k(en-us,vs.80).aspx

    Thanks,
       Ayman Shoukry
       VC++ Team.

  • Larry_Santos

    yeah in the class view in the C# application i could see the managed C++ dll variables that i did. but i cant in the code, why is that
  • Brian Gress

    but interoperability doesnt have anything to do with this, cause i already have the managed dll that i made using VC++ 2005.

    so in C# when i referenced the dll, and made an object, i should see the functions and variables automatically right thats how it should work.

    it even didnt see the variable that i had in the constructor in the managed c++ dll Sad.

  • Thomas Jakobsen

    Please share out  "file://c:\Documents and Settings\RamY\My Documents\Visual Studio Projects\MTokamak\Debug\BuildLog.htm"

    Also, how did you build tokamak.lib

    Thanks,
      Ayman Shoukry
      VC++ Team



  • MichaelY

    Did you try linking with the /NOENTRY linker switch as described in http://support.microsoft.com/ id=814472

    Thanks,
      Ayman Shoukry
      VC++ Team

  • lnk 2019 error