microsoft / microsoft/onnxruntime-inference-examples
build fails at linking stage, CXX option -fPIC not handed through
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 414
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 14
Description
I need to compile on Haiku (for this scenario, much like BSD).
The build runs fine until it tries to link the flatc submodule, where it fails with this error message, indicating the setting for position independent code is not respected:
[ 16%] Linking CXX executable flatc
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/13.3.0/../../../../x86_64-unknown-haiku/bin/ld: CMakeFiles/flatc.dir/src/idl_parser.cpp.o: relocation R_X86_64_PC32 against symbol `_ZTVN11flatbuffers9AllocatorE' can not be used when making a shared object; recompile with -fPIC
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/13.3.0/../../../../x86_64-unknown-haiku/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
_deps/flatbuffers-build/CMakeFiles/flatc.dir/build.make:656: recipe for target '_deps/flatbuffers-build/flatc' failed
make[2]: *** [_deps/flatbuffers-build/flatc] Error 1
CMakeFiles/Makefile2:7110: recipe for target '_deps/flatbuffers-build/CMakeFiles/flatc.dir/all' failed
make[1]: *** [_deps/flatbuffers-build/CMakeFiles/flatc.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2
...
subprocess.CalledProcessError: Command '['/bin/cmake', '--build', '/boot/home/Develop/SEN/NER/onnxruntime/build/Linux/Debug', '--config', 'Debug']' returned non-zero exit status 2.
Here's the config output from the start of the build:
-- ******** Summary ********
-- CMake version : 3.30.5
-- CMake command : /boot/system/bin/cmake
-- System : Haiku
-- C++ compiler : /bin/c++
-- C++ compiler version : 13.3.0
-- CXX flags : -fPIC -ffunction-sections -fdata-sections -Wno-restrict -DCPUINFO_SUPPORTED -Wnon-virtual-dtor
-- Build type : Debug
-- Compile definitions : ORT_ENABLE_STREAM;EIGEN_MPL2_ONLY;__STDC_FORMAT_MACROS
-- CMAKE_PREFIX_PATH : /boot/home/Develop/SEN/NER/onnxruntime/build/Linux/Debug/installed
-- CMAKE_INSTALL_PREFIX : /boot/system
-- CMAKE_MODULE_PATH : /boot/home/Develop/SEN/NER/onnxruntime/cmake/external
--
-- ONNX version : 1.16.1
-- ONNX NAMESPACE : onnx
-- ONNX_USE_LITE_PROTO : ON
-- USE_PROTOBUF_SHARED_LIBS : OFF
-- Protobuf_USE_STATIC_LIBS : ON
-- ONNX_DISABLE_EXCEPTIONS : OFF
-- ONNX_DISABLE_STATIC_REGISTRATION : OFF
-- ONNX_WERROR : OFF
-- ONNX_BUILD_TESTS : OFF
-- ONNX_BUILD_BENCHMARKS : OFF
-- ONNX_BUILD_SHARED_LIBS :
-- BUILD_SHARED_LIBS : OFF
--
-- Protobuf compiler :
-- Protobuf includes :
-- Protobuf libraries :
-- BUILD_ONNX_PYTHON : OFF
-- Could NOT find Eigen3 (missing: Eigen3_DIR)
PIC is set correctly in cmake/CMakeLists.txt and I even added the explicit -fPIC flag manually below (without that, the option does not show up in the compiler config output above):
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# seems not to be enough, so directly set -fPIC option
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
I also added these 2 settings to cmake/onnxruntime_common.cmake and to onnxruntime_flatbuffers.cmake just for testing, but to no avail.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with cmake/CMakeLists.txt, onnxruntime_common.cmake, and onnxruntime_flatbuffers.cmake, then inspect the generated _deps/flatbuffers-build files around the flatc target. Compare the compiler and linker flags on Haiku with the reported CXX configuration. Done means the flatc submodule links successfully on Haiku without the relocation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100