Undefined reference to `__ms_vsnprintf' when linking GLFW statically

天涯浪子 提交于 2019-11-30 19:12:45

问题


I am trying to compile the GLFW quickstart guide (Here) in windows 8 64-bit using mingw. I am using the official 32 bit windows binary from the glfw website.

Everything works fine when I link the glfw library dynamically by linking -lglfw3dll -lgdi32 -lopengl32 -lglew32 and defining GLFW_DLL.

When I try to link glfw statically, however, I get undefined reference to '__ms_vsnprintf'

My command to link statically is mingw32-g++.exe -o bin\Release\test.exe obj\Release\main.o -s -lglfw3 -lgdi32 -lopengl32 -lglew32s with GLEW_STATIC defined.


回答1:


I got the same problem when I tried to build an example app for GLFW. I switched the compiler suite from original MinGW32 to MinGW-W64 and that solved the problem. I came up with that idea after reading this post:

http://mingw-users.1079350.n2.nabble.com/missing-symbol-ms-vsnprintf-when-linking-with-cross-compiled-library-td7582798.html

Seems the GLFW libs are build with a MinGW64 or MinGW-W64.




回答2:


MinGW\include\stdio.h:

/* The following pair ALWAYS refer to the MSVCRT implementations...
 */
_CRTIMP int __cdecl __MINGW_NOTHROW _snprintf (char*, size_t, const char*, ...);
_CRTIMP int __cdecl __MINGW_NOTHROW _vsnprintf (char*, size_t, const char*, __VALIST);
_CRTIMP int __cdecl __MINGW_NOTHROW _vscprintf (const char*, __VALIST);

So just use them with underscore in front of them.



来源:https://stackoverflow.com/questions/29199720/undefined-reference-to-ms-vsnprintf-when-linking-glfw-statically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!