我能夠使用手寫的Makefile做到不CMake的,就像這樣:CMake的:從目標文件構建共享對象文件(的.so)時,在滿足依賴關係(的.o)
g++ $(CXSCINC) -c -fPIC cellComplex_extern.cpp -o cellComplex_extern.o
g++ $(CXSCINC) -shared -Wl -o cellComplex_lib.so cellComplex_extern.o $(CXSCLIB) -lcxsc
這讓我共享庫cellComplex_lib.so
,然後被接收爲動態鏈接庫(lib = ctypes.cdll.LoadLibrary('./cellComplex_lib.so'
)供以後使用。
我的項目已經轉移到CMake作爲一個構建系統,我正在模擬上面我的Makefile的功能。
到目前爲止,我已經發現了的CMakeLists.txt的add_library()
命令,但鏈接到CXSC庫從未(通過當我cmake
後運行make
可怕的抱怨就是明證。
我怎麼能告訴CMake的與第三方庫CXSC建立cellComplex_lib
- 非工作CMakeLists.txt
-
add_library(include/python/cellComplex_extern OBJECT
include/python/cellComplex_extern.cpp ${all_headers})
add_library(include/python/cellComplex_lib SHARED
include/python/cellComplex_extern)
target_link_libraries(include/python/cellComplex_lib ${CXSC_LIB_DIR}/libcxsc.a)
結果運行cmake的,隨後補充:
.
.
.
[ 75%] Built target include/python/cellComplex_extern
Linking CXX shared library libinclude/python/cellComplex_lib.dylib
ld: can't open output file for writing: libinclude/python/cellComplex_lib.dylib, errno=2 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libinclude/python/cellComplex_lib.dylib] Error 1
make[1]: *** [CMakeFiles/include/python/cellComplex_lib.dir/all] Error 2
make: *** [all] Error 2
好像你現在有路徑問題。或者正在使用的lib? – uncletall