3

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.

ikline
  • 33
  • 1
  • 3
  • 2
    Why do you have test.h in your command line and not included in your cpp? – djondal Aug 02 '10 at 18:08
  • There's absolutely no point in specifying specify an .h file in the command line. It achieves absolutely nothing. – AnT stands with Russia Aug 02 '10 at 18:11
  • It can achieves something if his header contain some executable code (functions definitions [and not only declared] or variables initialisation), you never know ... – djondal Aug 02 '10 at 18:18
  • Little harsh there andrey? It is in my cpp- I don't normally compile command line so I wasn't sure what to include. the -I. flag did it. – ikline Aug 02 '10 at 18:19

3 Answers3

5

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

Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
2

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
Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
XQYZ
  • 51
  • 3
2

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

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
djondal
  • 2,521
  • 3
  • 24
  • 40