[CMake] link errors using OpenMP

Brad King brad.king at kitware.com
Wed Oct 10 13:45:36 EDT 2012


On 10/08/2012 05:30 PM, Matthew Woehlke wrote:
> When I write a simple program using OpenMP, with a CMakeLists.txt like:
> 
> find_package(OpenMP REQUIRED)
> add_definitions(${OpenMP_CXX_FLAGS})
> add_executable(foo foo.cpp)

The value of OpenMP_CXX_FLAGS is CXX flags, not definitions.  Try:

 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")

CMake adds CXX flags on the link line when using the C++ compiler
to drive the link.  This is because flags like -m64 get used by
the front-end to choose implicit flags to pass to the linker.

In order to do it per-target, add it to the COMPILE_FLAGS and
LINK_FLAGS properties explicitly.

-Brad


More information about the CMake mailing list