【发布时间】:2021-05-29 17:31:17
【问题描述】:
我正在使用名为 libfstack(其文件名为 libfstack.a.1.21)的静态第三方库修改 mysql-server 8.0 源代码(开发源代码树)。但是作为一个CMake的初学者,我无法将第三方库正确链接到mysql项目。 如果您有任何想法,请告诉我。谢谢!
这是我执行make后得到的错误信息。
[ 67%] Built target clientlib_objlib
Scanning dependencies of target clientlib
[ 67%] Linking CXX static library ../archive_output_directory/libclientlib.a
[ 67%] Built target clientlib
Scanning dependencies of target libmysql
[ 67%] Building C object libmysql/CMakeFiles/libmysql.dir/libmysql_dummy.c.o
[ 67%] Linking CXX shared library ../library_output_directory/libmysqlclient.so
/usr/bin/ld: /usr/local/lib/libfstack/libfstack.a.1.21(libfstack.ro): relocation R_X86_64_TPOFF32 against `pcurthread' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libfstack/libfstack.a.1.21(ff_dpdk_pcap.o): relocation R_X86_64_TPOFF32 against `seq' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_dpaa.a(dpaa_bus.o): relocation R_X86_64_TPOFF32 against symbol `per_lcore_dpaa_io' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_dpaa.a(bman.o): relocation R_X86_64_TPOFF32 against `per_lcore_bman_affine_portal' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_dpaa.a(bman_driver.o): relocation R_X86_64_TPOFF32 against `bmfd' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_dpaa.a(qman.o): relocation R_X86_64_TPOFF32 against `per_lcore_qman_affine_portal' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_dpaa.a(qman_driver.o): relocation R_X86_64_TPOFF32 against `qmfd' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_fslmc.a(dpaa2_hw_dpio.o): relocation R_X86_64_TPOFF32 against symbol `per_lcore__dpaa2_io' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_bus_vdev.a(vdev.o): relocation R_X86_64_TPOFF32 against `per_lcore__thread_id.5396' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_eal.a(eal_thread.o): relocation R_X86_64_TPOFF32 against `per_lcore__thread_id.8400' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_eal.a(eal_vfio.o): relocation R_X86_64_TPOFF32 against `per_lcore__thread_id.8947' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_eal.a(eal_interrupts.o): relocation R_X86_64_TPOFF32 against `per_lcore__epfd' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_eal.a(eal_common_log.o): relocation R_X86_64_TPOFF32 against `per_lcore_log_cur_msg' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_eal.a(eal_common_errno.o): relocation R_X86_64_TPOFF32 against `per_lcore_retval.4583' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/librte_pmd_dpaa_sec.a(dpaa_sec.o): relocation R_X86_64_TPOFF32 against `dpaa_sec_op_nb' can not be used when making a shared object; recompile with -fPIC
我修改了源代码文件mysql_socket.h、mysqld.cc和socket_connection.cc。通过在所有项目文件中搜索这些文件名(尤其是在 xxx/CmakeLists.txt 中),我了解到它们仅与目标 sql_main 和 vio 相关。所以我做了以下cmake配置修改。 顺便说一句,我将系统环境变量 CFLAGS 和 CXXFLAGS 设置为“-fPIC -shared”,并使用这些标志构建了 libstack.a.1.21。 我做了我能做的一切,但仍然卡在上面提到的错误中。
以下是我在sql/CMakeLists.txt中添加的配置。 PS:我使用cmake成功构建了一个简单的helloworld程序,所以我确信这里列出了所有必要的库。
set_property(TARGET sql_main PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET sql_main PROPERTY BUILD_SHARED_LIBS true)
INCLUDE_DIRECTORIES(/usr/local/include)
INCLUDE_DIRECTORIES(/usr/local/include/dpdk)
TARGET_LINK_LIBRARIES(sql_main /usr/local/lib/libfstack/libfstack.a.1.21)
file(GLOB LIBOTHERS "/usr/local/lib/*.a")
TARGET_LINK_LIBRARIES(sql_main -Wl,--whole-archive ${LIBOTHERST} -Wl,--no-whole-archive)
TARGET_LINK_LIBRARIES(sql_main -lrt)
TARGET_LINK_LIBRARIES(sql_main -lm)
TARGET_LINK_LIBRARIES(sql_main -ldl)
TARGET_LINK_LIBRARIES(sql_main -lcrypto)
TARGET_LINK_LIBRARIES(sql_main -lpthread)
TARGET_LINK_LIBRARIES(sql_main -lnuma)
以下是我在vio/CMakeLists.txt中添加的配置。
set_property(TARGET vio PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET vio PROPERTY BUILD_SHARED_LIBS true)
INCLUDE_DIRECTORIES(/usr/local/include)
INCLUDE_DIRECTORIES(/usr/local/include/dpdk)
TARGET_LINK_LIBRARIES(vio /usr/local/lib/libfstack/libfstack.a.1.21)
file(GLOB LIBOTHERST "/usr/local/lib/*.a")
TARGET_LINK_LIBRARIES(vio -Wl,--whole-archive ${LIBOTHERST} -Wl,--no-whole-archive)
TARGET_LINK_LIBRARIES(vio -lrt)
TARGET_LINK_LIBRARIES(vio -lm)
TARGET_LINK_LIBRARIES(vio -ldl)
TARGET_LINK_LIBRARIES(vio -lcrypto)
TARGET_LINK_LIBRARIES(vio -lpthread)
TARGET_LINK_LIBRARIES(vio -lnuma)
【问题讨论】: