1

I am a bit confused by the way qt handles libraries. My plan was to put the external libraries I need into the source directory, so that a do not have to install them into the system. As this doesn't seem to work (see below) I was wondering, if this is generally a bad idea or if there is some trick to it??

So I compiled the libraries and put them into /mysubdir. In the .pro-file I added

LIBS+= -L"mysubdir" -l"mylib"

I got the compiler error [projectname] Error 2 and don't know what it means.

enam
  • 23
  • 1
  • 4
  • What's your platform? And can you post some more compiler output? Like e.g. what comes before Error 2. – ayoy Oct 17 '11 at 18:58
  • Ubuntu 10.04 "Lucid Lynx" (32bit) – enam Oct 17 '11 at 19:00
  • hm the last compiler output is "warning: control reaches end of non-void function". sorry, but I didn't find anything suspicious. – enam Oct 17 '11 at 19:05
  • what is strange is that I got the thing running once by uncommenting `pkg-config, but I couldn't reproduce it on my desktop (same operating system). Also this didn't seem to be the right way to do it... – enam Oct 17 '11 at 19:10
  • Yeah, 'Error 2' is just `make` error and it can mean anything. Does "mylib" contain only library name (without `.so` extension)? And you double checked "mysubdir" to correctly point to your library folder? – ayoy Oct 17 '11 at 19:27
  • Well, to be precise, I checked using `!exists(wcslibc/libwcs-4.8.2.a) {error( "No wcslibc/libwcs-4.8.2.a file found" )}` and the include line is `LIBS+= -L"wcslibc" -l"wcs-4.8.2" \ `. There is also a .so-file in the directory named libwcs.so.4.8.2, but `LIBS+= -L"wcslibc" -l"wcs" \ ` didn't work either – enam Oct 17 '11 at 19:47

1 Answers1

1

The argument passed to -L must be an absolute path. Please give it a try with a full path, or at least -L./wcslibc. Though I'm not sure whether ./ will be recognized correctly. You can get the current path in qmake like this:

LIBS += -L$${PWD}/wcslibc -lwcs
ayoy
  • 3,835
  • 19
  • 20
  • Thank you!! Now it seems to work. But why does it have to be the *.so file? I thought the *.a-file was "the library"... – enam Oct 17 '11 at 21:56
  • @enam: .so files are still libraries, they're just shared library files instead. – Nicholas Smith Oct 18 '11 at 10:01
  • Now I tried to run the thing on my desktop. And it doesn't work :-(. Using `LIBS += -L{PWD}/wcslibc -lwcs`, the library is not found. Using `LIBS += $${PWD}/wcslibc/libwcs.so.4.8.2`, the library is found at compile time, but not when running the program. I guess on my laptop I once did the "right" installation of the library into the system, which seems to make a difference. B.t.w. I in a very similar question the including seems to have worked (http://stackoverflow.com/questions/718447/adding-external-library-into-qt-creator-project) – enam Oct 18 '11 at 18:27
  • If a library is found during compilation and not found in runtime, you need to set library runpath. `LIBS += -L$${PWD}/wcslibc -Wl,-rpath,$${PWD}/wcslibc -lwcs` should work, that's how I used to get things working... I don't know the approach you mentioned (`LIBS += $${PWD}/wcslibc/libwcs.so.4.8.2`) - it might be some recent qmake feature, try adding `-Wl,-rpath,$${PWD}/wcslibc` to it. – ayoy Oct 18 '11 at 18:48
  • I tried `LIBS+= $${PWD}/wcslibc/libwcs.so.4.8.2 -Wl,-rpath,$${PWD}/wcslibc\`. It compiles with the warning "Must specify package names on the command line" (if that is helpful). But on run I still get **error while loading shared libraries: libwcs.so.4: cannot open shared object file: No such file or directory** – enam Oct 18 '11 at 19:14
  • `LIBS += -L$${PWD}/wcslibc -Wl,-rpath,$${PWD}/wcslibc -lwcs\` doesn't compile (/usr/bin/ld: cannot find -lwcs). The compiler seems to have a problem with the ".so.4.8.2"-extension. – enam Oct 18 '11 at 19:18
  • BTW, do you really have a file called `libwcs.so.4` or only `libwcs.so.4.8.2`? Try linking the former to the latter: `ln -s libwcs.so.4.8.2 libwcs.so.4` – ayoy Oct 18 '11 at 19:31