U¿ytkownik "Carl Daniel [VC++ MVP]"
The following compiles & links without error:
// lib1016.h
#ifndef lib1016_h_included
#define lib1016_h_included
extern void xxx(const char* ...);
#endif
// lib1016.cpp
#include "lib1016.h"
#include <stdarg.h>
#include <stdio.h>
void xxx(const char* fmt ...)
{
va_list args;
va_start (args, fmt);
vprintf(fmt,args);
va_end(args);
}
// Client1016.cpp
#include "lib1016.h"
int main(int argc, char* argv[])
{
xxx("argc %d, argv %p",argc,argv);
}
Copy the above text into three files (as indicated by the comments), compile
with
cl client1016.cpp lib1016.cpp
Yes these files compiles & links without error, but only when I include them
into one projects. When I create library "lib1016.lib", add library to
client1016 project - it compiles but linker reports an unresolved external
error. It's interesting that if I add "lib1016.obj" to client1016 project
linker reports no error!
If you're getting unresolved external errors from the linker, there's
something else about your project that's making the functions
incompatible.
The projects was created using standard VS creator (.NET Console
application, .NET Class library)
How are you compiling the library? The test program?
I use standard options (set by Visual Studio .NET 2003 creator) - the only
thing I change was to "don't use precompiled header"
- Calling convention: __cdecl (/Gd)
- Compile as C++ Code (/TP)
- Compile as managed: Assembly Support (/clr)
- Debug Information Format: Program Database (/Zi)
- Optimization: Disabled (/Od)
- Runtime library: Multi-threaded Debug (/MTd)
there are full command lines:
for library:
/Od /AI "C:\dotnet\jterm\Debug" /D "WIN32" /D "_DEBUG" /D "_MBCS" /FD /EHsc
/MTd /GS /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Zi /clr /TP /FU
"D:\WINNT\Microsoft.NET\Framework\v1.1.4322\mscorlib.dll" /FU
"D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll" /FU
"D:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /Zl
for test application:
/Od /AI "C:\dotnet\jterm\Debug" /D "WIN32" /D "_DEBUG" /D "_MBCS" /FD /EHsc
/MTd /GS /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /nologo /c /Zi /clr /TP
for linker:
/OUT:"C:\dotnet\jterm\Debug\client1016.exe" /INCREMENTAL /NOLOGO /DEBUG
/ASSEMBLYDEBUG /PDB:"C:\dotnet\jterm\Debug/client1016.pdb" /FIXED:No
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Use dumpbin /symbols
on the two .obj files to see how 'xxx' is decorated in each - is one C++
decorated and one undecorated? Are the calling conventions different?
No, calling conventions are the same. I run dumpbin tool on lib1016.lib file
and function __cdecl xxx(const char* ...) is in library!