我有以下CMakeLists:CMake的連接之前指定源
cmake_minimum_required(VERSION 3.3)
project(untitled)
set(SOURCE_FILES main.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/home/kernael/.openmpi/include -pthread -Wl,-rpath -Wl,/home/kernael/.openmpi/lib -Wl,--enable-new-dtags -L/home/kernael/.openmpi/lib -lmpi_cxx -lmpi")
add_executable(untitled ${SOURCE_FILES})
但構建似乎失敗,因爲CMake的自動設定後的「-l」選項中源(main.cpp中),這似乎是的問題,因爲命令行下面的命令工作:
g++ -I/home/kernael/.openmpi/include -pthread -L/home/kernael/.openmpi/lib main.cpp -lmpi_cxx -lmpi
但是這一次不和產生相同的錯誤,CMake的構建:
g++ -I/home/kernael/.openmpi/include -pthread -L/home/kernael/.openmpi/lib -lmpi_cxx -lmpi main.cpp
如何告訴CMake在鏈接發生之前指定源文件?