ikline
ikline

Reputation: 33

Using g++ to compile, how do I point it to other .h files?

I'm trying to compile a .cpp + .h file that includes newmat.h and tinyxml.h - I have libnewmat.a and libtinyxml.a in the same directory as my .cpp and .h files and I'm running

g++ -lnewmat -ltinyxml test.cpp test.h

but still getting newmat.h and tinyxml.h not found at the beginning of compilation. I'm obviously a total c++ newb because this seems like it should be trivial.

Upvotes: 3

Views: 5345

Answers (3)

XQYZ
XQYZ

Reputation: 51

The -I switch is used for that, for example:

g++ -I/usr/include -lnewmat -ltinyxml test.cpp test.h

And if you want to add a path to the Library Search-Path you use -L, for example:

g++ -L/usr/lib -lnewmat -ltinyxml test.cpp test.h

Upvotes: 2

djondal
djondal

Reputation: 2541

Try this one:

g++ -lnewmat -ltinyxml -I. test.cpp 

-I. to look the header files in the current folder and include your required .h in your .c files

Upvotes: 2

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143274

Use the -I flag to tell it what directory to look for include files.

Upvotes: 5

Related Questions