c++ - aarch64动态链接器rpath与辅助依赖关系链接的使用

我有两个共享库:liba和libb,其中libb取决于liba和使用libb的可执行文件。 在使用CMake进行aarch64架构构建项目时,我遇到了一个问题,而在主机工具链上一切正常。 该项目如下所示:

├── CMakeLists.txt
├── liba
│   └── main.cpp
├── libb
│   └── main.cpp
└── main
    └── main.cpp

CMakeLists.txt的内容如下:

cmake_minimum_required(VERSION 3.15)
project(my_proj CXX)

add_library(a SHARED liba/main.cpp)
set_property(TARGET a PROPERTY LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/a")
add_library(b SHARED libb/main.cpp)
set_property(TARGET b PROPERTY LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/b")
target_link_libraries(b PRIVATE a)

add_executable(main main/main.cpp)
target_link_libraries(main b)

使用我的主机g ++ / ld编译器/链接器,一切都可以正常工作。 但是,当我尝试使用ARM编译器构建项目时,出现链接器错误:

$ cmake .. -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
-- The CXX compiler identification is GNU 9.2.0
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/icblnk/tmp/rm/test/build
$ make
Scanning dependencies of target a
[ 16%] Building CXX object CMakeFiles/a.dir/liba/main.cpp.o
[ 33%] Linking CXX shared library a/liba.so
[ 33%] Built target a
Scanning dependencies of target b
[ 50%] Building CXX object CMakeFiles/b.dir/libb/main.cpp.o
[ 66%] Linking CXX shared library b/libb.so
[ 66%] Built target b
Scanning dependencies of target main
[ 83%] Building CXX object CMakeFiles/main.dir/main/main.cpp.o
[100%] Linking CXX executable main
/usr/lib/gcc/aarch64-linux-gnu/9.2.0/../../../../aarch64-linux-gnu/bin/ld: warning: liba.so, needed by b/libb.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc/aarch64-linux-gnu/9.2.0/../../../../aarch64-linux-gnu/bin/ld: b/libb.so: undefined reference to `function_liba_1()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:85: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

问题是CMake使用rpath ELF条目来查找PRIVATE库,由于某些原因,在ARM链接程序的情况下,该库不起作用。 我试图研究可能的链接器选项,但找不到任何有用的东西。

我在示例中使用的编译器/链接器版本:

$ ld --version
GNU ld (GNU Binutils) 2.32
$ aarch64-linux-gnu-ld --version
GNU ld (GNU Binutils) 2.32
$ g++ --version
g++ (GCC) 9.2.0
$ aarch64-linux-gnu-g++ --version
aarch64-linux-gnu-g++ (GCC) 9.2.0

转载请注明来自askonline.tech,本文标题:c++ - aarch64动态链接器rpath与辅助依赖关系链接的使用


 Top