-3

I'm working on a C++ project which is currently divided into "sub modules" / "components". Each of these are compiled into a separate library (components are usually 10-20 files). The libraries are linked to tests which ensure that each component works as expected.

I've now started to work on the "main" part of the project that is using all those different components. The problem is, that in the end I want to 'ship' this project as a dynamic library. I'm however running into problems linking libraries to a library. I'm not sure if this is because I am doing something wrong with my tools or if this is simply not possible.

As such, my question is:

Does my approach of having separate components be libraries so I can easily develop and test them individually make sense in C++, given that I want to deliver this project as a library itself?

  • 1
    Can the people who downvote actually explain why they are doing so? To me it seems like this is a typical project organization/structure question and as such a good fit for SE stackexchange, so please explain to me why you are downvoting so I can improve the question if needed! – Antiro42 May 27 at 20:02
  • I didn't downvote, but frankly this seems like common knowledge that could be obtained from any decent C++ book, and help with coding tools is off-topic here. – Robert Harvey May 27 at 20:08
  • I'll remove the (in CMake) part of the question and leave as a more general does it make sense to have a library project be composed of different libraries, would that make more sense? – Antiro42 May 27 at 20:09
  • Looks like there's some help here: stackoverflow.com/q/41322971 – Robert Harvey May 27 at 20:11
  • And here: stackoverflow.com/q/19424494 – Robert Harvey May 27 at 20:13
0

Does my approach of having separate components be libraries so I can easily develop and test them individually make sense in C++, given that I want to deliver this project as a library itself?

Yes, that approach makes sense and is not uncommon.

If your aim is to deploy a single dynamic library as your product, the main thing to look out for is that your components are build as static libraries (or both static and dynamic libraries if each component has multiple executables with unittests and you don't want the size of those executables to inflate).

In the end, this is not really related to C++, but more to how dynamic libraries work. Dynamic libraries are intentionally designed to be loaded as late as possible. This means that if a project tries to link to a dynamic library, that only has the effect to put a note in the resulting binary to load that dynamic library. And that binary can be a library itself.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.