Linker doesn't use a default runtime library when linking together libraries only (no objects)

荒凉一梦 提交于 2019-11-28 14:35:40

It turns out that the linker isn't clever enough to figure out what default runtime library is needed for the executable if only static libraries are given to link, with no discrete object files. This can be corroborated by asking the linker to be verbose in the .pro file:

win32-msvc*: QMAKE_LFLAGS += /VERBOSE /VERBOSE:LIB /VERBOSE:REF

When the dummy file is present in the application project, the linker lists the following default libraries:

Processed /DEFAULTLIB:msvcprt
Processed /DEFAULTLIB:MSVCRT
Processed /DEFAULTLIB:OLDNAMES
Processed /DEFAULTLIB:uuid.lib

Without the dummy file, no default libraries are chosen by the linker at all. It is then unable to find the entry point, since the C runtime is not linked in.

Adding the relevant C runtime library is sufficient to link the application. In the application project file, one adds:

win32-msvc*:CONFIG(release, debug|release): QMAKE_LFLAGS += /DEFAULTLIB:msvcrt
win32-msvc*:CONFIG(debug, debug|release): QMAKE_LFLAGS += /DEFAULTLIB:msvcrtd
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!