Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install libdrake.a C++ static library via CMake #16882

Open
aminya opened this issue Mar 29, 2022 · 4 comments
Open

Install libdrake.a C++ static library via CMake #16882

aminya opened this issue Mar 29, 2022 · 4 comments
Assignees
Labels

Comments

@aminya
Copy link
Contributor

aminya commented Mar 29, 2022

It seems that Bazel doesn't allow building a library as a static library by default, which is unfortunate as it means the users should either use the shared library or use Bazel as their build system all the way down.

There are multiple issues that report this in Bazel.
bazelbuild/bazel#1920
bazelbuild/bazel#492

There is one solution offered in the end. I tried it, but it lacks the libraries that Drakes uses (gflags).
bazelbuild/bazel#1920 (comment)

@jwnimmer-tri
Copy link
Collaborator

This sounds like a feature request on Drake, but I'm not sure exactly what feature you're requesting, or what problem you're trying to solve. Could you try to explain your desired result?

Would it solve the problem if when doing cmake && make install for Drake, that there was an option -DDRAKE_BUILD_STATIC=ON (off by default) that would install libdrake.a instead of libdrake.so?

If that's along the right path, then what should happen with the dependencies that are currently dynamically linked? Some of them are LGPL (LCM, dReal/IBEX), so we would either need to continue dynamically linking them, or else disable them.

Similarly, when building statically, we'd need to disable pydrake (since Python loadable native modules are basically always dynamic).

@jwnimmer-tri jwnimmer-tri self-assigned this Mar 29, 2022
@jwnimmer-tri jwnimmer-tri added component: distribution Nightly binaries, monthly releases, docker, installation type: feature request unused team: kitware labels Mar 29, 2022
@aminya
Copy link
Contributor Author

aminya commented Mar 29, 2022

This sounds like a feature request on Drake, but I'm not sure exactly what feature you're requesting, or what problem you're trying to solve. Could you try to explain your desired result?

Would it solve the problem if when doing cmake && make install for Drake, that there was an option -DDRAKE_BUILD_STATIC=ON (off by default) that would install libdrake.a instead of libdrake.so?

Yes, it will solve the issue. In fact, CMake has a built-in variable called BUILD_SHARED_LIBS, which will be ON when shared libraries are requested. You could use that for detecting the user preference.

The result will be a libdrake.a file in addition to the required header files and other runtime .so files that cannot be built statically.

If that's along the right path, then what should happen with the dependencies that are currently dynamically linked? Some of them are LGPL (LCM, dReal/IBEX), so we would either need to continue dynamically linking them, or else disable them.

The dynamic libraries that cannot be built statically (because of licensing or because of the way they are installed) should be installed/copied along with the static library.

Similarly, when building statically, we'd need to disable pydrake (since Python loadable native modules are basically always dynamic).

Yes. My request is for C++

@jwnimmer-tri
Copy link
Collaborator

Ok, this makes sense. The feature request is for our CMake build to obey BUILD_SHARED_LIBS to the extent possible.

We'll need to do #16780 first (so that we have a C++ standalone build, with no Python), and then we can return to this issue.

@jwnimmer-tri jwnimmer-tri changed the title Building as a static library Install Drake as a static library via CMake Apr 1, 2022
@jwnimmer-tri jwnimmer-tri changed the title Install Drake as a static library via CMake Install libdrake.a C++ static library via CMake Apr 1, 2022
@aminya
Copy link
Contributor Author

aminya commented Mar 8, 2024

I was able to get one minimal static library build of Drake working by patching Bazel and doing some hacks.
bazelbuild/bazel#16954 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants