PhotonLibOS
PhotonLibOS copied to clipboard
build:link error when using photon as cmake external project
使用cmake external project 把photon到项目中时,编译报错。不使用fetch_content的原因是网络环境不好,build是下载会很慢。。。
ExternalProject_Add(photon
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third/photonlibos
LOG_CONFIGURE
1
LOG_BUILD
1
LOG_INSTALL
1
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${STAGED_INSTALL_PREFIX}/photon
-DCMAKE_CXX_STANDARD=17
INSTALL_COMMAND cmake -E echo "Skipping install step.")
set(PHOTON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/third/photonlibos/include
CACHE PATH "Path to internally built PhotonLibOS include directory"
FORCE)
set(PHOTON_LIBRARY ${PROJECT_BINARY_DIR}/deps/Build/photon/output/libphoton.a
CACHE PATH "Path to internally build PhotonLibOS library"
FORCE)
ADD_LIBRARY(abc STATIC ${ABC_SOURCES})
TARGET_LINK_LIBRARIES(ts ${PHOTON_LIBRARY} ${FMT_LIBRARY})
link error:
[ 96%] Linking CXX executable cmake-external
/usr/bin/ld: /workspaces/cmake-external/build/deps/Build/photon/output/libphoton_sole.a(aio-wrapper.cpp.o): in function `photon::resume_libaio_requesters()':
aio-wrapper.cpp:(.text+0x3b8): undefined reference to `io_getevents'
/usr/bin/ld: /workspaces/cmake-external/build/deps/Build/photon/output/libphoton_sole.a(aio-wrapper.cpp.o): in function `libaio_wrapper_init':
aio-wrapper.cpp:(.text+0x954): undefined reference to `io_setup'
/usr/bin/ld: /workspaces/cmake-external/build/deps/Build/photon/output/libphoton_sole.a(aio-wrapper.cpp.o): in function `libaio_wrapper_fini':
aio-wrapper.cpp:(.text+0xabc): undefined reference to `io_destroy'
/usr/bin/ld: /workspaces/cmake-external/build/deps/Build/photon/output/libphoton_sole.a(aio-wrapper.cpp.o): in function `long photon::have_n_try<photon::libaiocb::cancel()::{lambda()#1}>(photon::libaiocb::cancel()::{lambda()#1} const&, char const*, long) [clone .isra.0]':
aio-wrapper.cpp:(.text._ZN6photon10have_n_tryIZNS_8libaiocb6cancelEvEUlvE_EElRKT_PKcl.isra.0[_ZN6photon8libaiocb15submit_and_waitEm]+0x54): undefined reference to `io_cancel'
/usr/bin/ld: /workspaces/cmake-external/build/deps/Build/photon/output/libphoton_sole.a(aio-wrapper.cpp.o): in function `photon::libaiocb::submit_and_wait(unsigned long)':
photon目前没提供cmake的install,只是给用户生成了target,然后target附带了一些依赖,希望用户直接把这些target加到自己的cmake里面去。
如果不用target的话,那可以走编译的方式,即你这种方法。但需要注意的是,libphoton_sole.a是指包含photon源码的静态库,不包含第三方库,如libaio.a,liburing.a 等。libphoton.a是所有静态库的打包,是在make的最后一步进行的,如果不用target引用的话,至少需要你主动调用make编译。看起来你是因为没有make,所以链接到了错误的静态库上去了,导致没有aio的符号
另外,不是 -D CMAKE_CXX_STANDARD ,而是 -D PHOTON_CXX_STANDARD ,参考官网文档 https://photonlibos.github.io/docs/introduction/how-to-build#build-options
感谢回复。我试试