Skip to content

build fails at linking stage, CXX option -fPIC not handed through #503

Open
@grexe

Description

@grexe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions