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

前端 未结 1 1532
故里飘歌
故里飘歌 2020-12-12 06:23

I want the users to be able to re-link my Qt-using application to their own build of Qt, without being forced to rebuild all of the sources. This could be used for LGPL comp

1条回答
  •  忘掉有多难
    2020-12-12 07:13

    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
    

    0 讨论(0)
提交回复
热议问题