我在嘗試構建一個靜態庫並將其用於編譯一個 fortran文件。如果我做的:在CMake中查找目錄
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
add_library(mylib STATIC ${lib_src}/mylib.for)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
add_executable(bin/out ${PROJECT_SOURCE_DIR}/src/program.f)
target_link_libraries(bin/out mylib)
那麼它所有的作品(注意庫內置到二進制文件目錄 根,但FORTRAN編譯成子目錄);但是,如果我做
set(archives ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
add_library(mylib STATIC ${lib_src}/mylib.for)
find_library(mylib NAMES mylib PATHS ${archives})
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
add_executable(bin/out ${PROJECT_SOURCE_DIR}/src/program.f)
target_link_libraries(bin/out mylib)
,當我跑我得到一個錯誤的cmake:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
mylib linked by target "bin/out" in directory /home/chris/project
如果我離開了最後2行,然後存檔文件並獲得 寫入到lib子目錄,作爲libmylib.a預期。如果我做
set(archives ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
add_library(mylib STATIC ${lib_src}/mylib.for)
find_library(mylib NAMES mylib PATHS ${archives})
include_directories(${archives})
set(libs ${libs} ${mylib})
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
add_executable(bin/out ${PROJECT_SOURCE_DIR}/src/program.f)
target_link_libraries(bin/out {LIBS})
然後CMake的命令運行正常,但運行make然後生成 編譯錯誤(我知道set命令和target_link_libraries 變量不同的情況 - 的東西我不明白 是一個爲什麼這隻在make運行時失敗,而不是cmake;如果 變量是相同的大小寫,那麼我得到與上面相同的錯誤)。
那麼,我怎樣才能讓CMake識別在CMake運行期間創建的我的${PROJECT_BINARY_DIR}/lib
文件夾?有人能指出我的 (可能很明顯)的錯誤嗎?!