5

I have both static and dynamic versions of Boost installed in /usr/local/lib, i.e. both libboost_system.dylib and libboost_system.a exist.

In my qmake project file I've added the Boost libraries to the linker like so: LIBS += -lboost_system

Can I tell qmake to prefer the static versions without explicitly stating the filename, so that I can reduce the amount of qmake code to get static linking on all platforms?

Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
  • If I understood your question correct, you can find answer here http://www.qtcentre.org/wiki/?title=Building_static_applications – CAMOBAP Jun 30 '14 at 15:22

2 Answers2

0

It seems that this is not really possible, and specifying absolute paths to libraries is a much better solution (i.e. how CMake does it by default).

Jake Petroules
  • 23,472
  • 35
  • 144
  • 225
  • But this doesn't handle static dependencies nicely. For example, Boost might depend on zlib but it is not pulled in automatically. This is especially a problem for mingw. – Timothy Gu Nov 26 '14 at 19:40
0

I have not used qmake, but there is a way to make gcc link to a static lib by put -static flags to linker. All libs that you want to link statically should put after this flag.

I searched for qmake's document, and found that you can modify the link flags by change the variable QMAKE_LFLAGS, or may directly add this flag to LIBS

user685684
  • 182
  • 7
  • I did try that but encountered the same problem described here: http://stackoverflow.com/questions/844819/how-to-static-link-on-os-x Also that would seem to imply that there is no way to prefer static libraries without simply specifying the full filename. I'll leave this open for a while so someone can confirm either way. – Jake Petroules Apr 02 '12 at 04:15
  • 1
    I found this: http://stackoverflow.com/questions/4156055/gcc-static-linking-only-some-libraries, so try `LIBS += -static -lsomelib --Wl,-Bdynamic`? – user685684 Apr 02 '12 at 04:20