Error when statically building a windows application

こ雲淡風輕ζ 提交于 2019-12-10 20:22:06

问题


I have an application that compiles and works fine when i dynamically link everything, but when I want to have a static build of it it will not compile.

In visual studio 2010 I set the Use MFC in a Static Library option.

When I do that I get this error:

Error 1 error LNK2001: unresolved external symbol _wWinMain@16 LIBCMT.lib(wwincrt0.obj)

I have tried adding LIBCMT.lib as an additional library, but that doesn't change anything.

Any ideas on how to fix this problem?


回答1:


From the message that it's missing WinMain that implies to me that some piece of your project is being built as an application and NOT as a library.

Try a full rebuild and ensure that all relevant options are set to build a static library. I believe libcmt.lib should only be linked to your final application, NOT to the library.




回答2:


When you build the program, there are compiler flags to set Unicode/MBCS, Multi/Single threaded and various other things. If you compile some source with one set of flags and other source with different flags, then you often get linker errors like that.

Check that all the source uses the same flags, including any of your own libraries.

The specific error you have says that the linker is including the binary wwincrt0.obj from library LIBCMT.lib. wwincrt0.obj is referring to a function wWinMain() and the linker doesn't know where to find it.

LIBCMT is the multi-threaded version of LIBC. You will link to one of those, but never both.

wwincrt0 is the wide (UNICODE) version of the CRT (C Run Time) startup code, which will launch your code.

WinMain() is the Windows main function and wWinMain() is the wide (UNICODE) version of WinMain().

I will guess that some of your code is compiled with the compiler flag /MT and some is compiled with a different flag (/MTd, /MD, /MDd, /LD or /LDd).

My second giess would be that some is compiled with /DUNICODE and some with /DMBCS.



来源:https://stackoverflow.com/questions/5836644/error-when-statically-building-a-windows-application

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