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?
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.
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:
- Move the library source code to a separate directory
- Menubar "project"
- Menu "properties" will open a dialog box for all the project properties there will be a list on the left.
- 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]
- GCC C Compiler --> Directories:
- Green plus icon [2] --> Specify the path of your *.h files
- 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 )
- GCC C Linker --> Libraries:
- Library search path (-L) --> Green plus icon --> Specify the path of your *.lib files
- Libraries (-l) --> Green plus icon --> Specify the name of each library you are using
- 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:
- Do the same steps above except in step 7.
- 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.