Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Static Qt with static MSVC C++ library
Forum Updated to NodeBB v4.3 + New Features

Static Qt with static MSVC C++ library

Scheduled Pinned Locked Moved Installation and Deployment
11 Posts 2 Posters 14.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    philippeb8
    wrote on last edited by
    #1

    Hi,

    I am compiling an application statically with no problem but I would like to use the static version of the MSVC C++ library. To do so I use:
    QMAKE_CFLAGS_RELEASE += /MT
    QMAKE_CXXFLAGS_RELEASE += /MT

    But I get multiple definitions of the same symbol:
    ...
    MSVCRT.lib(MSVCR100.dll) : error LNK2005: __open_osfhandle already defined in LIBCMT.lib(osfinfo.obj)

    Is there an easy solution or should I tell the linker to accept multiple symbols?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Since you are refering to MSVC C++ I would assume that you are also using visual studio. You could install "vsaddin ":http://developer.qt.nokia.com/wiki/QtVSAddin
      There is no need to use qmake explicitely.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        philippeb8
        wrote on last edited by
        #3

        One way or the other the actual flag to accept multiple symbols is:
        QMAKE_LFLAGS_RELEASE += /FORCE:MULTIPLE

        But it still creates an executable relying on:
        MSVCP100.dll
        MSVCR100.dll

        And I would like to get rid of those DLL dependencies.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          I have just compiled a small project with /MT option. I was compiling with dlls before.
          First recompilation it complaint that I need to specify /NODEFAULTIB
          Second recompilation gave loads of error messages. Probable I would need to adjust more settings, which I can't do today.

          BTW: I am using Win 7 64 bit and msvc2005.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            philippeb8
            wrote on last edited by
            #5

            Any luck?

            1 Reply Last reply
            0
            • P Offline
              P Offline
              philippeb8
              wrote on last edited by
              #6

              It looks like with MSVC you need to tell at compile-time DLL or LIB dependencies. This means you need to rebuild QT to use static VC libraries. Go to ${QtDir}\mkspecs\win32-msvc2010\qmake.conf, and replace

              QMAKE_CFLAGS_RELEASE = -O2 -MD
              QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
              QMAKE_CFLAGS_DEBUG = -Zi -MDd

              with

              QMAKE_CFLAGS_RELEASE = -O2 -MT
              QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi
              QMAKE_CFLAGS_DEBUG = -Zi -MTd

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                I was able to setup a small "hello world" application with -MT. When I add Qt it will require dlls, because I do not have a static Qt compilation. So, that is logical.
                Did you succeed with your application?

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  philippeb8
                  wrote on last edited by
                  #8

                  I need to rebuild the Qt libraries using the settings previously mentioned, so it'll take me another 2 hours. I might as well add the following compilation flag: /Gy and link the final executable with /OPT:REF. This way it'll remove unused functions. And voila!

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    philippeb8
                    wrote on last edited by
                    #9

                    Just for the records I found a nmake clone that uses all the available cores on the system... just like "-jX" of make:
                    http://labs.qt.nokia.com/2009/03/27/speeding-up-visual-c-qt-builds/

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #10

                      [quote author="philippeb8" date="1310852943"]Just for the records I found a nmake clone that uses all the available cores on the system... just like "-jX" of make:
                      http://labs.qt.nokia.com/2009/03/27/speeding-up-visual-c-qt-builds/[/quote]

                      Yes, jom may reduce your overall compilation time cosiderably.

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        koahnig
                        wrote on last edited by
                        #11

                        [quote author="philippeb8" date="1310747680"]
                        MSVCRT.lib(MSVCR100.dll) : error LNK2005: __open_osfhandle already defined in LIBCMT.lib(osfinfo.obj)

                        Is there an easy solution or should I tell the linker to accept multiple symbols?[/quote]
                        As answer to your initial question: You may also exclude LIBCMT (option: NODEFAULTLIB:LIBCMT). This is eliminating the multiple definitions warning/error.

                        However, for msvc2005 there is an error:
                        @
                        error LNK2019: unresolved external symbol _WSAAsyncSelect@16 referenced in function "public: void __thiscall EventDispatcherWin32Private::doWsaAsyncSelect(int)" (?doWsaAsyncSelect@QEventDispatcherWin32Private@@QAEXH@Z)
                        @
                        This error is there also when LIBCMT has not been ignored, respectively, also accepting multiple definitions does not help. Could be an msvc2005 specific problem.

                        Vote the answer(s) that helped you to solve your issue(s)

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved