2014-03-03 29 views
0

我能夠使用手寫的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 
+0

好像你現在有路徑問題。或者正在使用的lib? – uncletall

回答

1

我認爲你需要使用target_link_libraries

target_link_libraries(include/python/cellComplex_lib ${CXSLIB}) 

這是我的Win32開發過程中使用了什麼:

link_directories(${LIB_ROOT_DIR}/lib ${LIB_ROOT_DIR2}/lib/morelibs) 
add_library(MyDll1 SHARED File1.cpp File2.cpp) 
add_library(MyDll2 SHARED File3.cpp File4.cpp) 
add_dependencies(MyDll2 Dll1) 
target_link_libraries(MyDll2 Dll1 some.lib another.lib) 

在這裏,您指定該Dll2需要Dll1和另外兩個外部庫。

+0

當目標是我剛添加了'add_library'的庫時,我似乎無法使用'target_link_libraries()'。錯誤是'ld:無法打開輸出文件寫入:'。我嘗試了更多的東西並編輯我的問題。不過謝謝,我認爲這非常接近我正在尋找的東西。 –

+0

在這種情況下,您需要添加add_dependency,我會將其添加到答案中 – uncletall

相關問題