2015-05-04 74 views
1

我想在我的項目中包含SFML源代碼。我的目錄是這樣佈局的:來自子目錄的CMake鏈接庫

main 
    SFML (subtree synced with the official git repo) 
    src 
    <various modules> 
    General (here lies the binary) 

從主層我先添加SFML子目錄然後src。正如我見過看着構建的日誌,這將產生庫:

sfml‑system 
sfml‑window 
sfml‑network 
sfml‑graphics 
sfml‑audio 
sfml‑main 

現在,我想他們在總目錄這樣的鏈接到我的二進制:

add_executable(main ${main_SRCS}) 
target_link_libraries (main 
    sfml‑system 
    sfml‑window 
    sfml‑network 
    sfml‑graphics 
    sfml‑audio 
    sfml‑main 
    # Other stuff here 
) 

,但我得到:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsfml‑system 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsfml‑window 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsfml‑network 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsfml‑graphics 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsfml‑audio 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.2/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsfml‑main 

爲什麼CMake嘗試使用系統庫而不是剛剛構建的系統庫,以及如何解決這個問題?

+0

那些庫是同一個CMake項目的目標嗎?如果是這樣,是'sfml-system'等目標的實際名稱? –

+0

頂級CMakeLists作用: 'add_subdirectory(SFML) add_subdirectory(SRC)' 我可以看到生成日誌庫名稱: 'CXX鏈接共享庫../../../lib/ libsfml-graphics.so等 – Tommalla

+0

@BaummitAugen我剛剛意識到SFML子目錄定義了自己的項目。我想這會回答你的問題,並以某種方式改變我的東西? – Tommalla

回答

1

這應該是正常的。

試圖與CMake的3.2在Windows上的Visual Studio發電機和發電機的Makefile在Linux上執行以下操作:

project(test) 

cmake_minimum_required(VERSION 2.8) 

add_subdirectory(SFML-2.2) 

add_executable(foo bar.cpp) 
target_link_libraries(foo sfml-system) 

SFML正確和正確地sfml-systemfoo鏈接建立。

您從另一個子目錄生成可執行文件的事實不應該在這裏產生影響。

的事項還真是,add_subdirectory調用發生之前target_link_libraries,使CMake的已經知道sfml-system目標的唯一的事。

+0

您的回答是正確的,但由於某些原因在m y項目(然而,在虛擬項目中工作)。出於這個原因,我選擇它作爲接受的答案。 – Tommalla