views:

64

answers:

2

hi!

I have two precompiled library: X.a and Y.a and a test.cpp (without main function) source code use these two libraries.

I compiled the C++ using:

g++ -c test.cpp

and I got 'test.o'.

Now how can I link these three together to generate a .a file because test.cpp use some function in X.a and Y.a and other GCC libraries?

BTW, I am doing these under Windows using MinGW. Can I rename this .a file to .lib and use this .lib in VC?

Thanks!

+1  A: 

In order to add your object file to the static library you have to use the following command:

ar rcs X.a test.o

But if you are provided with X.a and Y.a I suppose you are not the author of X and Y, therefore I'm not sure you really want to join them!

You may decide to link every object file into a single executable instead, but you need the main function for it!

EDIT: Also I suggest you to read this.

Dacav
Thanks. The problem is that I need to use GCC to get a static library and use VC to link this static library as I have done some fortran stuff in GCC..
David
@David: unfortunately I don't know anything about VC, but it seems that vartec gave you some useful info.
Dacav
+2  A: 

Now how can I link these three together to generate a .a file because test.cpp use some function in X.a and Y.a and other GCC libraries?

.a is nothing more then ar archive containg all object files (.o files)

Can I rename this .a file to .lib and use this .lib in VC?

Yes, but it requires little trick to work. See: http://opensees.berkeley.edu/community/viewtopic.php?t=2267

vartec