0

Possible Duplicate:
Howto compile a static library in linux

I'm trying to compile a library that will be used further.

For each cpp file, of this library, is generating a .o file. How can I make the same compilation with only one .o file?

4
  • 2
    You link all the .o files together to make an .a file. Commented Jan 7, 2013 at 18:21
  • 5
    Why? Sounds like the XY problem. Commented Jan 7, 2013 at 18:21
  • @SethCarnegie how can I do that? Commented Jan 7, 2013 at 18:26
  • @Victor ar rcs some.a 1.o 2.o ..., see stackoverflow.com/q/2734719/726361 (I assume it's a static library) Commented Jan 7, 2013 at 18:38

1 Answer 1

2

You can not build a single .o file from multiple C++ source files. Compilers just can't handle that.

If the library comes with a proper build infrastructure (like Makefiles), that should make a libXXX.a or libXXX.so file that you can reference from your own project.

If the library does not create a lib-file by itself, you can create one with

ar -r libXXX.a <list of .o files>
Sign up to request clarification or add additional context in comments.

1 Comment

"You can not build a single .o file from multiple C++ source files." -- Actually, he can, he just doesn't want to. As you correctly observe, he wants to build a .a library.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.