1
我試圖編譯測試子目錄project/model/tests
可執行文件需要鏈接駐留在project/model
我的模型文件的可執行文件。但是,我無法讓它工作。我已經成功地將父目錄,但CMake的不斷告訴我發現Foo.cpp中沒有源文件,該文件是在父目錄,而bar.cpp,這是在當前目錄中,正確添加。添加從父目錄cmake的
cmake_minimum_required(VERSION 2.6)
# get parent directory
get_filename_component(MODEL_DIR ${CMAKE_CURRENT_SOURCE_DIR} PATH)
# Locate GTest
find_package(GTest REQUIRED)
# Add parent directory
include_directories(${GTEST_INCLUDE_DIRS} ${MODEL_DIR})
link_directories(${MODEL_DIR})
# all included directories are printed out correctly
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
# foo.cpp, which is in the parent directory is not found
add_executable(runTests foo.cpp bar.cpp)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread)
謝謝。
謝謝。它現在可以工作:)而且我會嘗試關注你對link_directories的建議。 –
@LimH。給出'link_libraries()'警告的一些基本原理:參見例如[這個問題](http://stackoverflow.com/q/15423821/1782465)例如與它的問題。 – Angew