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

Shared library linking fails #362

Open
jlheflin opened this issue Dec 27, 2024 · 4 comments
Open

Shared library linking fails #362

jlheflin opened this issue Dec 27, 2024 · 4 comments

Comments

@jlheflin
Copy link
Contributor

jlheflin commented Dec 27, 2024

[ 80%] Linking CXX shared library libpluginplay.so
/usr/bin/ld: _deps/utilities-build/libutilities.a(demangler.cpp.o): warning: relocation against `_ZTINSt8__detail11_AnyMatcherINSt7__cxx1112regex_traitsIcEELb1ELb0ELb0EEE' in read-only section `.text._ZNSt17_Function_handlerIFbcENSt8__detail11_AnyMatcherINSt7__cxx1112regex_traitsIcEELb1ELb0ELb0EEEE10_M_managerERSt9_Any_dataRKS8_St18_Manager_operation[_ZNSt17_Function_handlerIFbcENSt8__detail11_AnyMatcherINSt7__cxx1112regex_traitsIcEELb1ELb0ELb0EEEE10_M_managerERSt9_Any_dataRKS8_St18_Manager_operation]'
/usr/bin/ld: _deps/utilities-build/libutilities.a(demangler.cpp.o): relocation R_X86_64_PC32 against symbol `_ZNSt5ctypeIcE2idE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/pluginplay.dir/build.make:427: libpluginplay.so.1.0.41] Error 1
make[1]: *** [CMakeFiles/Makefile2:294: CMakeFiles/pluginplay.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

I get this error when building with cmake -S . -B build -DNWX_MODULE_DIRECTORY=/home/jacob/Projects/PluginPlay/install when building with shared libraries. If the option is set to off, then the build is able to complete.

@ryanmrichard
Copy link
Member

It looks like you are building PluginPlay as a shared library, but (I assume implicitly) telling PluginPlay to build Utilities as a static library without -fPIC.

Is that your entire build command? Are you using a toolchain file? If so, what is the contents of your toolchain file?

FWIW, the build instructions you've been using to build GhostFragment should work for building PluginPlay too.

@jlheflin
Copy link
Contributor Author

Sorry for the delayed reply.

All I do to build any of the projects is cmake -S . -B build -DNWX_MODULE_DIRECTORY=/path/to/dir/ and then I will use the TUI program ccmake to edit the install prefix. I just retried the same build instructions for GhostFragment on the export_property_types branch and I get a successful compilation. During the compilation of PluginPlay utilities is compiled as a static library, a setting that I don't set myself.

@ryanmrichard
Copy link
Member

I strongly recommend using a toolchain file or a build script over 'ccmake'. It's very difficult to reproduce builds done with 'ccmake'.

Building static libraries is CMake's default. You will either need to set BUILD_SHARED_LIBS and/or CMAKE_POSITION_INDEPENDENT_CODE to true. I recommend doing this in a toolchain to make sure the dependencies see it.

@jlheflin
Copy link
Contributor Author

I will use a toolchain.cmake file from now on. The problem remedies if ccmake is used to view the build directory variables. The differences in the CMakeCache.txt between the two is negligible, with the main differences between CMAKE_INSTALL_PREFIX, CMAKE_MODULE_PATH, and _GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX. Here is the differences before and after a ccmake command, where --- denotes the ccmake CMakeCache.txt, and +++ denotes the CMakeCache.txt before the ccmake command:

--- /home/jacob/Projects/PluginPlay/build/CMakeCache.txt
+++ /home/jacob/diff.txt
@@ -176,7 +176,7 @@
 //C header files for non-gcc (/usr/include)
 CMAKE_INSTALL_OLDINCLUDEDIR:PATH=/usr/include
 
-CMAKE_INSTALL_PREFIX:PATH=/usr/local/lib/pluginplay/external/lib/pluginplay/external
+CMAKE_INSTALL_PREFIX:PATH=/usr/local/lib/pluginplay/external
 
 //Run-time variable data (LOCALSTATEDIR/run)
 CMAKE_INSTALL_RUNSTATEDIR:PATH=
@@ -216,7 +216,7 @@
 // RELWITHDEBINFO builds.
 CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=
 
-CMAKE_MODULE_PATH:STRING=;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/cmaize-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/cmakepp_lang-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/parallelzone-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/cmakepp_lang-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/parallelzone-src/cmake
+CMAKE_MODULE_PATH:STRING=;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/cmaize-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/cmakepp_lang-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/nwx_cmake-src/cmake;/home/jacob/Projects/PluginPlay/build/_deps/parallelzone-src/cmake
 
 //Path to a program.
 CMAKE_NM:FILEPATH=/usr/bin/nm
@@ -1010,7 +1010,7 @@
 //linker supports push/pop state
 _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED:INTERNAL=TRUE
 //CMAKE_INSTALL_PREFIX during last run
-_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX:INTERNAL=/usr/local/lib/pluginplay/external
+_GNUInstallDirs_LAST_CMAKE_INSTALL_PREFIX:INTERNAL=/usr/local
 _PYBIND11_CROSSCOMPILING:INTERNAL=OFF
 _Python:INTERNAL=Python
 //Compiler reason failure

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

No branches or pull requests

2 participants