0

If I have a directory structure such as the tree below, what should my g++ command look like that would successfully compile the .cpp file that is in the taglib/bin dir, with all my .h files sitting in the taglib/include/taglib directory.

Anyones help would be greatly appreciated. Thank you!

-taglib

--bin
  .cpp file is here, incl headers are like this: #include <other.h>
  but wondering if it should be #include </taglib/include/taglib/other.h>,
  also, this should be where my binary will live when compiled.

--lib
  all my .so files live here

--include
---taglib
   all my .h files live here 
cube
  • 1,774
  • 4
  • 23
  • 33

1 Answers1

2

The -I and -L options specify search directories for includes and libraries respectively. Therefore, you command should be something like:

g++ -o <xyz> taglib/bin/*.cpp -Iinclude/taglib -Llib

man gcc and even gcc --help gives great information on these particular command line options (and the GCC manual is fairly friendly too). You should really be trying them first before you ask here - it's more efficient (no waiting for answers!).

Matthew Iselin
  • 10,400
  • 4
  • 51
  • 62
  • 3
    Thankfully, your paths don't exactly match the question, so cube may have to work them out for himself and learn something after all. – Ben Voigt Feb 07 '11 at 23:05
  • 1
    @Ben Voigt, so, what are you saying... by me asking a question here, I am NOT trying to learn? well, let me say that I am happy for you that you're an expert, but I am just learning c++. Even the man pages can be ALOT confusing and convoluted at times. So please forgive me! – cube Feb 07 '11 at 23:33
  • @Mathew, thanks that has helped me. I in fact did read the man page, but couldn't really pinpoint what switches to use and where and google'ing it just took me all over the place. Thanks again. – cube Feb 07 '11 at 23:43
  • @cube: when reading man pages and related documentation to figure out how to do something, I highly recommend you pick out a couple keywords and speculate as to what the feature might be called. For example, here you would speculate that you are looking for "include directories" (this might be trial & error). Then you can search Google/SO/man pages/whatever for "include directories" in the context of GCC - at this point you will be MUCH closer to your solution and can refine the keywords down. – Matthew Iselin Feb 07 '11 at 23:53
  • @cube: for example, the second Google result (here) for "gcc include directories" is http://www.network-theory.co.uk/docs/gccintro/gccintro_22.html, which explains the concept. This will come with practice though as you "learn how to learn" and is a useful skill not only in programming but in almost any situation where you need an answer to something you don't know. – Matthew Iselin Feb 07 '11 at 23:54
  • @cube: No, I'm not saying you're not TRYing to learn. I'm saying that you will learn more from an answer which gives you the building blocks to solve your problem that one which spoon-feeds you the answer. Too many people on this site have a gimme-teh-codez attitude and will be back with a very slight variation on the same problem because all they got from the first answer was a magic incantation, not understanding. I'm glad you don't want to be one of them. – Ben Voigt Feb 08 '11 at 00:42