views:

1373

answers:

2

I've gotten some C++ code to work with the TinyXML parser. However, to do this I had to include the source code from TinyXML with my regular source code. I'd like to have TinyXML included as a separate library. I'm using Eclipse with the Cygwin C++ compiler. What's a good way to do this?

+1  A: 

It's basically easy. You compile your source code for the library, and construct the library with ar(1). Yes, surprise, a library is just an archive; UNIX is cool that way.

You can then include the code as a static library when you build the final code.

I don't use Eclipse all that much so I can't tell you the exact process within the IDE, but I believe what you need is to set up a separate project to build it.

Now, if what you want is to build a DLL, then you need to use some special flags. There's a nice page here.

Charlie Martin
+2  A: 

I assume you want to separate the library from your own project's source code... but you don't know how to build when the library is not in the same folder.


Assuming your library has precompiled *.lib and *.h files:

  1. Move the library source code to a separate directory
  2. Menubar "project"
  3. Menu "properties" will open a dialog box for all the project properties there will be a list on the left.
  4. List item "C/C++ Build" will change the GUI and show you all the options for gcc's compiler/linker/assembler ( I never do assembly... so I never do anything with the assembler ). [1]
  5. GCC C Compiler --> Directories:
  6. Green plus icon [2] --> Specify the path of your *.h files
  7. Your compiler should now be happy ( but you will fail linking because the linker doesn't know what the actual definitions of each function are )
  8. GCC C Linker --> Libraries:
  9. Library search path (-L) --> Green plus icon --> Specify the path of your *.lib files
  10. Libraries (-l) --> Green plus icon --> Specify the name of each library you are using
  11. Your linker should now be happy and your code should compile

[Footnote - 1] The GUI C/C++ build pane is a wrapper for gcc's command line compiler/linker... it is just making it easier to use because it shows you everything visually.

[Footnote - 2] The '+' icon is what will tell the compiler where your libraries *.h include files are located. The compiler needs the *.h files to know what function prototypes your library has before it compiles.


Assuming you have the actual ( not compiled ) *.c and *.h:

  1. Do the same steps above except in step 7.
  2. At step 7. you need to make sure the library's *.c files are seen by Eclipse's "managed make". If it doesn't see the source code then you need to specify where the source is so that it will compile it.
Trevor Boyd Smith
At the moment, I don't have Eclipse on this computer... and I don't remember exactly what that Eclipse option is... but I will edit my answer as soon as I get to a computer with Eclipse. In the mean time others can feel free to chip in.
Trevor Boyd Smith
Thanks for the detailed answer!
Jack BeNimble