-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
[compile error] Linker errors when building static libs with PCL_BUIILD_SHARED=OFF
#4377
Comments
It looks like the problem is caused by the line
in file
I found that when trying to build pcl 1.11.1 as a static library. I'm getting this error:
My setup is
and cmake is generally able to find OpenGL. I verified that by running
Adding
fixes the error, whereas adding Digging into the history revealed an interesting fact: in the case
was commented in file
Well, it looks like even in static build Linux requires to find shared libraries. So, the line
must be deleted, and this should fix the problem. |
If you believe this resolves the issue, please issue a PR 🎉 |
That may avoid the error, but through accepting dynamic libs as well, and I think they'll mostly be preferred if both dynamic and static versions are available. The result may be static |
PCL's cmake allows each dependency to be explicitly chosen as static, so there's some control over that process (if that's what you're asking) |
I'll prepare the PR soon. In any case, pcl should not force users to choose only between "all-static" and "all-dynamic" alternatives. That is too rigid. A better solution is to support "I-dont-care" scenario by default, where pcl just compiles with whatever dependencies are found, making random choices if both static and dynamic versions of a dependency are available to choose from. If the user wants a control over how pcl dependencies are build, the user should use a package manager like conan or vcpkg. A package manager represents each dependency of pcl, direct or indirect, is a separate package. Pcl may suggest the default settings for its dependencies, but the user has the ultimate control whether to build each individual package as a static or shared library, and what other options to choose for each package. Considering this, |
My CMake skills are pretty bad. PRs to augment are welcome 😄 🎊 awaiting PR 🎊 |
We have had some trouble mixing static and dynamic version of the libraries: see #1601 (comment). But it would be nice that it automatically find either static/dynamic of qhull, boost and flann. They have some explicit variables like: PCL_BUILD_WITH_BOOST_DYNAMIC_LINKING_WIN32 etc. |
After reviewing #1601, my understanding is that the problem there was due to failure to call This initialization issue is not unique to VTK: it exists for any library, static or dynamic, which has to do a non-trivial initialization at startup. The only clean way to implement that is to provide in the library itself an initialization function, and then kindly ask any application that uses that library to call the provided initialization function before starting using the library. It is not possible (at least, on Windows) to cleanly auto-initialize a library without the help from the application. With dynamic libraries, one might attempt to perform the initialization from
This works regardless whether VTK is built as static or dynamic library. So, I think the problem in #1601 was more about proper initialization of VTK rather than about mixing static and dynamic versions of the libraries. As long as all pcl applications that use VTK make the needed |
Describe the error
Compilation of 1.11.0 fails when build configured with
cmake .. -DPCL_SHARED_LIBS=OFF -DWITH_OPENGL=OFF -DCMAKE_VERBOSE_MAKEFILE=1
.The errors are of the form
and occur for some compilation units, but others build fine. One affected target is
pcl_pcd_introduce_nan
.To Reproduce
cmake .. -DPCL_SHARED_LIBS=OFF -DWITH_OPENGL=OFF -DCMAKE_VERBOSE_MAKEFILE=1
make -j8
Screenshots/Code snippets/Build information
The cmake output is this
Your Environment (please complete the following information):
If PCL was compiled from source or failure in compiling PCL itself:
Possible Solution
Some googling suggested this may be due to the fact that libc is not linked statically, maybe some flags like
-static-libgcc
or-static-libstdc++
are missing? Then again from what I read, one should not attempt to statically link libgcc. However this means the option to build static libpcl appears not to work in this configuration. It seems though that when I add-static -static-libstdc++ -static-libgcc
toCMAKE_CXX_COMPILE_FLAGS
that linking succeeds, but I had to explicitly configure-DWITH_VTK=OFF
.Update: Without adding the compiler flags, I manually removed
/usr/lib/x86_64-linux-gnu/libpthread.a
from the compiler invocation and then the target builds. I did not find a way to force cmake to not link pthreads dynamically. TheCMAKE_FIND_LIBRARY_SUFFIXES
get set to ".a" when building static libs. I tried switching this temporarily to ".so" for thefind_packge(Threads)
call, but that does not help. maybe because the lib is also brought in through another dependency such as OpenMP?The text was updated successfully, but these errors were encountered: