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

lnk 2019 error
Oscar Thornell
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
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
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> </td><td width=0 bgcolor=#FFFFFF> </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> </td><td width=0 bgcolor=#FFFFFF> </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 "WIN32" /D "_DEBUG" /D "_MBCS" /D "_WINDLL" /FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\MTokamak2005.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /c /Zi /clr:oldSyntax /TP /FU "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.dll" /FU "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.Data.dll" /FU "c:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\System.XML.dll"
".\MTokamak2005.cpp"
]
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:"C:\Documents and Settings\RamY\My Documents\Visual Studio 2005\Projects\MTokamak2005\Debug\MTokamak2005.dll" /INCREMENTAL /DLL /MANIFEST /MANIFESTFILE:"Debug\MTokamak2005.dll.intermediate.manifest" /DEBUG /ASSEMBLYDEBUG /PDB:"c:\documents and settings\ramy\my documents\visual studio 2005\projects\mtokamak2005\debug\MTokamak2005.pdb" /MACHINE:X86 /FIXED:No /NOENTRY
".\debug\MTokamak2005.obj"
".\debug\AssemblyInfo.obj"
".\debug\Stdafx.obj"
".\debug\app.res"
]
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:"..\debug\MTokamak2005.dll;#2" /manifest
".\debug\MTokamak2005.dll.intermediate.manifest"
]
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% > ".\debug\mt.dep"
]
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> </td><td width=0 bgcolor=#FFFFFF> </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> </td><td width=0 bgcolor=#FFFFFF> </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#
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
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
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
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
Brian Gress
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
Thomas Jakobsen
Also, how did you build tokamak.lib
Thanks,
Ayman Shoukry
VC++ Team
MichaelY
Thanks,
Ayman Shoukry
VC++ Team