A bit of context. Say I have source files that should be in a static library. Let's say there are two cpp a.cpp and a.cpp located in two different subdirectories. Something like that:
foo/ah foo/a.cpp bar/ah bar/a.cpp
Their content does not collide and is completely different. The file names are the same.
Now, when compiling, I get, of course, two ao files.
gcc -c foo/a.cpp -o foo/ao gcc -c bar/a.cpp -o bar/ao
If I create a static lib now with
ar rcs libfoobar.a foo/ao bar/ao
I can see both files inside the nm libfoobar.a static library nm libfoobar.a . Seems beautiful.
Problem
The problem that I see is that I run the ar command separately for foo/ao and bar/ao , putting them in the same static library. Now the last file of the object will overwrite the first, so when I start nm libfoobar.a I just see the last object in the library. I guess this is because of the same object name.
When creating a static library with ar , should I always merge all objects at a time or is it also normal to run ar several times collecting some of the objects at a time, all ending in the same static library? In this example, I see the first works, but not the last.
How will everything work when one a.cpp changes and the static library needs to change? Will ar find the correct a.cpp to change in the library?
This is just a small example, but consider a large project with many files, and some with the same name. If now you want to create one library, you can cope with this situation too.
In general, is this just a poor organization of how libraries are compiled, what are the files called, or is there something else for this?