question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] How to build third-party static libs with -fPIC

See original GitHub issue

I’m trying to inject the -fPIC setting into a third-party lib based on CMake. I followed the steps described in the Bincrafters documentation but it didn’t work like that.

The documentation claims that internally something like this happens:

cmake.definitions[‘CMAKE_POSITION_INDEPENDENT_CODE’] = self.options.fPIC

However, this doesn’t seem to be true.

I noticed that only the CONAN_CMAKE_POSITION_INDEPENDENT_CODE variable is set in the CMake definitions. The CMake run itself states that this variable is set but was not used by the project. The conan source seems to define a CMake macro called conan_set_fpic, that should handle this variable but nobody is calling that macro. In the end, nobody sets the CMAKE_POSITION_INDEPENDENT_CODE variable.

What’s the idea behind all this and how can I solve it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fschoenmcommented, Feb 21, 2020

The CMake build helper will do it automatically if: […]

That’s my understanding now as well.

The Bincrafters documentation made it sound like it should work even if the CMake project is not setup for it. It even works if you copy the code from the documentation that sets CMAKE_POSITION_INDEPENDENT_CODE manually. So my confusion came from the fact that it doesn’t do that automatically.

Thanks for the clarification, anyway.

0reactions
czoidocommented, Feb 21, 2020

Thanks, @fschoenm, as it seems to be clear I will close the issue, please feel free to reopen if you have further questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - Combining third-party static libraries into a stand-alone ...
Following answers might be useful: How to combine several C/C++ libraries into one? and Merge multiple .so shared libraries.
Read more >
Makefile errors using gfortran -static option - Fortran Discourse
The obvious question is what do I do to install the static libraries? Best check the documentation of your system package manager.
Read more >
Building And Using Static And Shared "C" Libraries
Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all...
Read more >
Static and Dynamic Libraries - Nick Desaulniers
It covers working with static and dynamic libraries in Linux and OSX. Make sure to check out the first on object files and...
Read more >
Creating and using shared libraries with different compilers on ...
In this article I focus on shared libraries and give a practical overview on how to create and use shared libraries with various...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found