开发者

gcc -I and -L options don't seem to work

I am trying to compile a project in my system using qmake. Some dependencies of the project are not installed but reside in my home directory, more or less like this: libs files: /home/myusername/local/lib and my includes directory /home/myusername/local/include. Inside the include directory I have a folder, qjson with the needed headers from the library. In the lib folder I have the files libqjson.so libqjson.so.0 libqjson.so.0.7.1.

My qmake project file looks something like this:

linux-g++ {
INCLUDEPATH += /home/myusername/local/include/
LIBS += -L/home/myusername/local/lib/ -lqjson
}

and the generated makefile will produce commands like this one:

g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB \
    -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../qbuzz \
    -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui \
    -I/usr/include/qt4 -I/home/myusername/local/include/ -I. -I. -I../myproject -I. \
    -o qbuzz-result.o ../myproject/myfile.cc

I开发者_高级运维t is clear that my include directory is in the -I option of gcc. myfile.cc contains an include like this one:

#include <qjson/parser.h>

However, after running make, I get the error:

../myproject/myfile.cc:2:26: fatal error: qjson/parser.h: No such file or directory
compilation terminated.

Now, if I modify the environment variable CPLUS_INCLUDE_PATH to add my local include file, I have no problems there, but in the linker stage I got the error:

/usr/bin/ld: cannot find -lqjson
collect2: ld returned 1 exit status

Even though the linker command was:

g++ -omyprogram main.o mainwindow.o myfile.o moc_mainwindow.o -L/usr/lib \
    -L/home/myusername/local/lib/ -lqjson -lQtGui -lQtNetwork -lQtCore -lpthread 

I also can get around modifying the environment variable LIBRARY_PATH. However I am looking for a solution that relies on modifying as few environment variables as possible, and after all, why are the options -L and -I there?

I works on Windows without problems using MinGW g++.


I notice that the QT's automatic include paths have no trailing slashes, and yours do. Have you tried writing the paths without trailing slashes?

linux-g++ {
 INCLUDEPATH += /home/myusername/local/include
 LIBS += -L/home/myusername/local/lib -lqjson
}


G++ and friends (i.e. as, ld, etc) will not directly tell you exactly where it looks for header and library files. One way to debug this is to run strace -o output.txt -eopen -s 1024 -f qmake. This will run qmake logging all open system calls of qmake and all of the child processes it forks. You will then be able to see in what directories and in what order it searches for header files (and libraries). Example output extract for stdio.h:

26069 open("/usr/lib/gcc/x86_64-redhat-linux/4.6.0/include/stdio.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory)
26069 open("/usr/local/include/stdio.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory)
26069 open("/usr/include/stdio.h", O_RDONLY|O_NOCTTY) = 4
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜