to compile a library from multiple sources
I want to bu开发者_如何学编程ild a library from multiple source files, like a1.cpp a2.cpp. I used the following command, 'g++ -o libcode -c a1.cpp a2.cpp'. However, error pop up "cannot specify -o with -c or -S with multiple files".
In general, how should I build such lib from multiple sources? thanks...
You first compile your source files to objects files (*.o
), and then invoke the ar command to build the library. In your example:
g++ -c a1.cpp a2.cpp
ar rcs libcode.a a1.o a2.o
This would build a static library, you can also create a dynamic one.
http://www.network-theory.co.uk/docs/gccintro/gccintro_79.html
http://tldp.org/HOWTO/Program-Library-HOWTO/static-libraries.html
精彩评论