How do I make a static library Release/Debug indep

2019-07-23 04:05发布

问题:

I am programming an application and linking against SDL and OpenGL. In my code I have the following lines:

#pragma comment(lib, "sdl.lib")
#pragma comment(lib, "sdlmain.lib")
#pragma comment(lib, "opengl.lib")

This works in Release mode only. In Debug mode, I receive the following linker error:

libcmt.lib(invarg.obj) : error LNK2005: __initp_misc_invarg already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: __call_reportfault already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: __set_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: __get_invalid_parameter_handler already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invoke_watson(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invoke_watson@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: "void __cdecl _invalid_parameter(unsigned short const *,unsigned short const *,unsigned short const *,unsigned int,unsigned int)" (?_invalid_parameter@@YAXPBG00II@Z) already defined in LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj) : error LNK2005: ___pInvalidArgHandler already defined in LIBCMTD.lib(invarg.obj)
libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

I have compiled SDL from source for my application, so I can control the compiler flags.

When I specify /NODEFAULTLIB:"LIBCMT.LIB" or /NODEFAULTLIB:"LIBCMT" for the project SDLMain, the utility dumpbin.exe still reports the following after compilation for sdlmain.lib:

Linker Directives
-----------------
/DEFAULTLIB:"LIBCMT"
/DEFAULTLIB:"OLDNAMES"

These linker directives do not appear when I use dumpbin against the opengl.lib (which came with VS2010 Express). The opengl.lib works in both Release and Debug modes. The sdl.lib works in both release and debug modes because, I think, it is a DLL lib and not a static lib.

What am I doing wrong here?

EDIT:

I managed to get it to compile and link by adding /NODEFAULTLIB:LIBCMT.LIB to my own Debug configuration instead of SDLMain. I also assumed that the OpenGL lib was a static library, but it's not, it's a DLL lib also.

回答1:

In vs2005 in project configuration, under linker options, I would set "ignore specific library" to libcmt.lib . vs2010 config might be similar. In any case, please try to ignore libcmt.lib and see what happens.

-- pete