I want to create a library that lets my programs to use one class, lets call it A, which has some neat methods and so on… This class, though, relies on a few others (B and C), and it includes their .hpp files in its .cpp file.
The build process goes like this:
g++ -c B.cpp
g++ -c C.cpp
g++ -c A.cpp
ar rvs A.a *.o
By doing this, my other projects now only need to files to include my A class, A.hpp and A.a. Am I making a static library correctly? Should I only put A.o in the archive (library) (doing so produces errors)?
Just for reference, this is how a program using the A class is compiled:
g++ test1.cpp A.a -o test1
Edit: is there a way to implicitly tell the linker to link my program with A.a? Just like I don’t manually need to link it with iostream…
That’s fine how you’re doing it now. Put all the object files into the static library.