问题描述
我正在编写一个应用程序并链接到SDL和OpenGL。在我的代码中,我有以下行:
#pragma comment(lib,sdl.lib)
# pragma注释(lib,sdlmain.lib)
#pragma注释(lib,opengl.lib)
b $ b
这只能在释放模式下工作。在调试模式下,我收到以下链接程序错误:
libcmt.lib(invarg.obj):error LNK2005:__initp_misc_invarg在LIBCMTD.lib(invarg.obj)
libcmt.lib(invarg.obj):错误LNK2005:__call_reportfault已在LIBCMTD.lib(invarg.obj)中定义
libcmt.lib错误LNK2005:__set_invalid_parameter_handler已在LIBCMTD.lib(invarg.obj)中定义
libcmt.lib(invarg.obj):错误LNK2005:__get_invalid_parameter_handler已在LIBCMTD.lib(invarg.obj)中定义
libcmt.lib (invarg.obj):error LNK2005:__invoke_watson已在LIBCMTD.lib(invarg.obj)中定义
libcmt.lib(invarg.obj):error LNK2005:void __cdecl _invoke_watson(unsigned short const *已经在LIBCMTD.lib(invarg.obj)中定义的
libcmt.lib(invarg.obj):错误LNK2005:LIBCMTD.lib(invarg.obj)中定义的函数(*,unsigned short const *,unsigned int,unsigned int) __invalid_parameter已在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)
libcmt.lib(invarg.obj):error LNK2005:___pInvalidArgHandler已在LIBCMTD.lib(invarg .obj)
libcpmtd.lib(xdebug.obj):warning LNK4098:defaultlib'libcmt.lib'与其他库的使用冲突;使用/ NODEFAULTLIB:库
我已经为我的应用程序从源代码编译SDL,所以我可以控制编译器
当我为项目SDLMain指定/NODEFAULTLIB:\"LIBCMT.LIB或/ NODEFAULTLIB:LIBCMT时,实用程序dumpbin.exe仍然会报告以下内容: sdlmain.lib的编译:
链接器指令
-------------- ---
/ DEFAULTLIB:LIBCMT
/ DEFAULTLIB:OLDNAMES
对opengl.lib(VS2010 Express附带)使用dumpbin时,不会出现这些链接器指令。 opengl.lib在发布和调试模式下工作。 sdl.lib在发布和调试模式下都工作,因为我认为它是一个DLL库而不是一个静态库。
我在这里做错了什么? / p>
编辑:
我设法通过添加/NODEFAULTLIB:LIBCMT.LIB到我的自己的Debug配置而不是SDLMain。我也假设OpenGL库是一个静态库,但它不是一个DLL库。
在vs2005项目配置,在链接器选项下,我会将忽略特定库设置为libcmt.lib。 vs2010 config可能是类似的。在任何情况下,请尝试忽略libcmt.lib,看看会发生什么。
- pete
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.
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
这篇关于如何使VS2010 Express中的静态库发布/调试独立?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!