qhull / qhull

Qhull development for www.qhull.org -- Qhull 2020.2 (8.1-alpha1) at https://github.com/qhull/qhull/wiki
Other
716 stars 191 forks source link

Failed to link libqhullstatic_r.a to a shared library on linux #107

Open larshg opened 2 years ago

larshg commented 2 years ago

See https://dev.azure.com/PointCloudLibrary/pcl/_build/results?buildId=20517&view=logs&j=9d3980c9-0219-58cf-8caa-f76ff3e2f24a&t=5bf54fc2-bd9f-533d-02a6-0ecd7f58b56a&l=32458.

It seems the flag -fPIC is not present in the current Cmake build files.

Should we enable it generally or only for the static libraries? ie. add set(CMAKE_POSITION_INDEPENDENT_CODE ON)

or set it per target.

cbbarber commented 2 years ago

POSITION_INDEPENDENT_CODE is set for qhull_CPP (#47). Is another change needed?

fPIC is tricky to get right. It apparently needs matching settings in multiple places.

See the discussion and changes made for Install pkg-config from Makefile #63

Can someone suggest the best way to resolve larshg's problem?

larshg, Please extract the relevant log lines from your build. Also the build link is no longer applicable.

SpaceIm commented 1 year ago

A rule of thumb is that PIC should never be hardcoded in build files of libraries (anything which is not a usage requirement of a library should not be hardcoded in build files), except when some object or static target is linked to a shared library internally. It's the responsibility of users to properly inject PIC (just inject -DCMAKE_POSITION_INDEPENDENT_CODE=ON during CMake configuration) when they build an external static library intended to be linked to a shared library.

(In conan package manager, we have to patch qhull CMakeLists to remove these hardcoded CMAKE_POSITION_INDEPENDENT_CODE).

HemaZ commented 1 year ago

@SpaceIm Did you have to make a custom conan recipe for Qhull? I'm trying to build the one from conan-center now but im getting these errors


-- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Check size of off_t
-- Check size of off_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for ftello
-- Looking for ftello - found
-- Looking for PRIdMAX
-- Looking for PRIdMAX - found
-- 
-- ========== qhull Build Information ==========
-- Build Version:                             8.0.1
-- Install Prefix (CMAKE_INSTALL_PREFIX):     /media/ibrahim/ExSSD/Conan/data/qhull/8.0.1/_/_/package/6b7ff26bfd4c2cf2ccba522bfba2d2e7820e40da
-- Binary Directory (BIN_INSTALL_DIR):        bin
-- Library Directory (LIB_INSTALL_DIR):       lib
-- Include Directory (INCLUDE_INSTALL_DIR):   include
-- Documentation Directory (DOC_INSTALL_DIR): share/doc/qhull
-- Man Pages Directory (MAN_INSTALL_DIR):     share/man/man1
-- Build Type (CMAKE_BUILD_TYPE):             RelWithDebInfo
-- To override these options, add -D{OPTION_NAME}=... to the cmake command
--   Build the debug targets                  -DCMAKE_BUILD_TYPE=Debug
-- 
-- To build and install qhull, enter "make" and "make install"
-- To smoketest qhull, enter "ctest"
-- 
-- Configuring done

CMake Error: failed to create symbolic link 'libqhull.so.8.0': operation not permitted
CMake Error: cmake_symlink_library: System Error: Operation not permitted
CMake Error: failed to create symbolic link 'libqhull.so': operation not permitted
CMake Error: cmake_symlink_library: System Error: Operation not permitted
make[2]: *** [CMakeFiles/libqhull.dir/build.make:355: libqhull.so.8.0.1] Error 1
make[2]: *** Deleting file 'libqhull.so.8.0.1'
make[1]: *** [CMakeFiles/Makefile2:271: CMakeFiles/libqhull.dir/all] Error 2
[ 86%] Linking CXX static library libqhullcpp.a
[ 86%] Built target qhullcpp
[ 87%] Linking C shared library libqhull_p.so
CMake Error: failed to create symbolic link 'libqhull_p.so.8.0': operation not permitted
CMake Error: cmake_symlink_library: System Error: Operation not permitted
CMake Error: failed to create symbolic link 'libqhull_p.so': operation not permitted
CMake Error: cmake_symlink_library: System Error: Operation not permitted
make[2]: *** [CMakeFiles/qhull_p.dir/build.make:355: libqhull_p.so.8.0.1] Error 1
make[2]: *** Deleting file 'libqhull_p.so.8.0.1'
make[1]: *** [CMakeFiles/Makefile2:297: CMakeFiles/qhull_p.dir/all] Error 2
[ 87%] Linking C static library libqhullstatic_r.a
[ 87%] Built target qhullstatic_r
make: *** [Makefile:146: all] Error 2

not sure why it tries to build a shared library even if

-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF

did you have a similar issue?


Update:

It turned out that the library was trying to build some shared libraries and I have Conan/Data directory on an external HDD, so cmake couldn't create symbolic links for these shared libs.

cbbarber commented 7 months ago

I agree with spacelm's comment that CMAKE_POSITION_INDEPENDENT_CODE should be the user's responsibility.

Is it (1) better to leave CMakeLists.txt as is or (2) revert #47 and thus remove 'POSITION_INDEPENDENT_CODE' from the qhull_CPP configuration? If reverted, users who depend on this setting will need to update their build scripts.