下面的cmake文件是问题的根源,因为我可以直接用mpic ++编译代码而不使用cmake。
为什么下面的cmake文件不起作用?
当前的cmake文件:
cmake_minimum_required(VERSION 2.8)
project(boost_mpi_cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable(test test.cpp)
find_package(Boost REQUIRED mpi system)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(test ${Boost_LIBRARIES})
find_package(MPI REQUIRED)
include_directories(${MPI_CXX_INCLUDE_PATH})
target_link_libraries(test ${MPI_CXX_LIBRARIES})
TEST.CPP:
#include <boost/mpi.hpp>
#include <iostream>
#include <string>
namespace mpi = boost::mpi;
int main()
{
mpi::environment env;
mpi::communicator world;
std::string s(env.processor_name());
std::cout << s << "\n";
return 0;
}
错误:
Undefined symbols for architecture x86_64:
"boost::mpi::environment::processor_name[abi:cxx11]()", referenced from:
_main in test.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [test] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
在没有cmake的情况下编译:
mpic++ test.cpp -lboost_mpi