LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to include library directories? (https://www.linuxquestions.org/questions/programming-9/how-to-include-library-directories-156660/)

davee 03-12-2004 06:15 AM

How to include library directories?
 
I'm trying a simple QT tutorial. When I try and compile my helloworld app, it has trouble including the .h files (see below). Where and how do I include the directory containing these (I think it's /opt/kde3/qt/include)...

dave@davee:~/qt> qmake -project
dave@davee:~/qt> qmake
dave@davee:~/qt> make
g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -DNO_DEBUG -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -fPIC -DNO_DEBUG -DQT_NO_DEBUG -I/usr/lib/qt3//mkspecs/default -I. -I. -I/usr/include -I/include -o main.o main.cpp
main.cpp:1:26: qapplication.h: No such file or directory

cjp 03-12-2004 07:50 AM

I don't know much about qmake & QT, but I know that make uses a file called Makefile. Try to find the -I. -I/usr/include etc. arguments in Makefile, and add "-I/opt/kde3/qt/include". That should work, but I'm not sure if Makefile is auto-generated by qmake. If that is the case, then you should check qmake's input files / configuration to make sure that it also writes this argument in newly-written Makefiles

bigearsbilly 03-12-2004 07:56 AM

from man make

Code:

    -Idir
          Append  directory  dir  to  the  list  of  directories
          searched for include files.

try adding -I blah/blah/include it to your CFLAGS variable.

bigearsbilly 03-12-2004 07:56 AM

oops! i mean 'man gcc'

deiussum 03-12-2004 09:00 AM

You seem to be under the impression that libraries and .h files are the same thing. Your title mentions library directories, then you ask about the directory containing .h files in the text.

A library and a .h file are NOT the same. A library contains object code that has the actual implementation of things. A .h file simply DECLARES the implementation of those things, it doesn't implement them.

So... even if you get your INCLUDE paths working, the next thing you will probably run into is linker errors because you don't have the LIBRARY paths setup. To tell the linker about a LIBRARY, you use -llibraryname and possibly -L/path/to/library if it is not in your search paths.

Sorry, if you are already aware of the distinction, but it was always a bit of a pet peeve of mine when people in my C++ classes in college would say they included a library, when what they really did was to include a header file... :) I think the confusion might have come from the fact that the standard C/C++ libraries are usually included by default so they never had to deal with actual libraries before.

woodywellhung 04-04-2004 04:53 PM

and dont forget that -llibraryname is not the actual filename either.

i.e. if you want to link a file called libMylib.a

you would actually use

gcc -l Mylib

cjp 04-05-2004 02:20 AM

Quote:

you would actually use

gcc -l Mylib
Without the space between -l and Mylib. So, you should do this:

gcc -lMylib

woodywellhung 04-05-2004 05:41 AM

Quote:

Without the space between -l and Mylib. So, you should do this:
-lMylib
should be fine with or without the space but I was taught that not having one is depreciated.


All times are GMT -5. The time now is 03:25 AM.