Reputation: 11
I'm modifying mysql-server 8.0 source code (development source tree) using a static third-party library called libfstack (whose file name is libfstack.a.1.21). But as a beginner of CMake, I cannot link the third-party library to the mysql project correctly. Please let me know if you have any idea. Thanks!
This is the error message I got after executing 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
I modified source code file mysql_socket.h, mysqld.cc and socket_connection.cc. By searching these file names in all project files (especially in xxx/CmakeLists.txt), I got that they are only related to target sql_main and vio. So I did following cmake configuration modifications. By the way, I set the system env variable CFLAGS and CXXFLAGS to "-fPIC -shared" and built the libstack.a.1.21 with these flags. I did everything I could, but still got stuck to the error mentioned above.
Following is the configuration I added in the sql/CMakeLists.txt. PS: I built a simple helloworld program using cmake successfully, so I'm sure all necessary libraries are listed here.
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)
Following is the configuration I added in the 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)
Upvotes: 1
Views: 323
Reputation: 5520
The issue is that libfstack
wasn't compiled with -fPIC
enabled and you're trying to link it into a shared library. You wrote that you set CFLAGS
and CXXFLAGS
to -fPIC -shared
when recompiling libfstack
, but I suspect that added -shared
caused that recompilation to only build the shared version of the library, leaving the old libfstack.a.1.21
as it was before.
Alternatively, if you don't want to recompile libfstack
you need to ensure that mysql-server
doesn't build shared libraries. Usually that can be done by using -DBUILD_SHARED_LIBS=OFF
, but seeing set_property(TARGET vio PROPERTY BUILD_SHARED_LIBS true)
in the CMakeLists.txt
you posted I'm afraid that mysql-server doesn't allow switching between static and shared builds out of the box. So you'd need to go in change it manually.
Upvotes: 1