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

Enable POSITION_INDEPENDENT_CODE for FMS CMake #806

Closed
mathomp4 opened this issue Sep 1, 2021 · 2 comments · Fixed by #930
Closed

Enable POSITION_INDEPENDENT_CODE for FMS CMake #806

mathomp4 opened this issue Sep 1, 2021 · 2 comments · Fixed by #930
Labels
enhancement Issue/PR for a modification that increases performance, improves syntax, or adds functionality.

Comments

@mathomp4
Copy link
Contributor

mathomp4 commented Sep 1, 2021

Is your feature request related to a problem? Please describe.

I've been trying to build GEOS with the latest FMS and after not being able to do it with Autotools (see #805), I went back to CMake build and I got close. So close except I got a message like:

relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

It wasn't exactly this, but my terminal lost the real error as I stupidly had only like 100 lines of playback. ☹️

The main issue is that we build MOM6 as a shared object library, but as far as I can tell, FMS builds as a static library (libfms_r4.a). Or it least, as I have it set up, that's how it built for me.

We've encountered this before with some of our Baselibs and the usual solution is to "add -fPIC" or in CMake terms...

Describe the solution you'd like

Add:

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

to CMakeLists.txt

I did this in my 2021.03 checkout at line 51 and...it worked.

Describe alternatives you've considered

I guess I could try building FMS as a shared object library, but I'm not sure how. My scan of its CMake and instructions didn't seem to show how.

Now, the question is: does setting this hurt you? I don't think it should as it just adds -fPIC everywhere and that's nigh-standard nowadays.

@mathomp4 mathomp4 added the enhancement Issue/PR for a modification that increases performance, improves syntax, or adds functionality. label Sep 1, 2021
@mathomp4 mathomp4 mentioned this issue Sep 1, 2021
8 tasks
@mathomp4
Copy link
Contributor Author

mathomp4 commented Sep 1, 2021

Note: There is also the "per target" version:

set_target_properties(mylib PROPERTIES POSITION_INDEPENDENT_CODE ON)

but I'm usually lazy and do it globally. 😄

@aerorahul
Copy link
Contributor

@mathomp4
We should be able to choose at build time to build a shared or static FMS library (or both).
It will need minimal modifications to CMakeLists.txt and I know what needs to be done to enable this.

If you want, I can provide a patch/branch for you to test with GEOS in the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue/PR for a modification that increases performance, improves syntax, or adds functionality.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants