[cmake-developers] [CMake 0015392]: Unclear documentation for module: FindOpenMP.cmake

Mantis Bug Tracker mantis at public.kitware.com
Mon Feb 9 10:58:10 EST 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=15392 
====================================================================== 
Reported By:                Mathieu Malaterre
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15392
Category:                   CMake
Reproducibility:            have not tried
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-02-09 10:58 EST
Last Modified:              2015-02-09 10:58 EST
====================================================================== 
Summary:                    Unclear documentation for module: FindOpenMP.cmake
Description: 
The FindOpenMP module states:

[...]
       The following variables are set:

          OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
[...]

Instead is should be stated that the OpenMP flags should be passed both to the C
compiler and the linker.

Eg, the following will not work (linker step will fail)

cmake_minimum_required(VERSION 2.8)
project(omp C)
find_package(OpenMP REQUIRED)
# OPENMP_FOUND

# Not OK
# pass OpenMP flag to C compiler (only)
set_property(SOURCE tomp.c
  PROPERTY COMPILE_FLAGS ${OpenMP_C_FLAGS}
  )

# OK
# pass OpenMP CFLAGS to C compiler and linker:
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")

add_executable(tomp tomp.c)

Steps to Reproduce: 
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(omp C)
find_package(OpenMP REQUIRED)
# OPENMP_FOUND

# Not OK
# pass OpenMP flag to C compiler (only)
set_property(SOURCE tomp.c
  PROPERTY COMPILE_FLAGS ${OpenMP_C_FLAGS}
  )

# OK
# pass OpenMP CFLAGS to C compiler and linker:
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")

add_executable(tomp tomp.c)

$ cat tomp.c
#include <math.h>

int main()
{
  const int size = 256;
  double table[size];

  int n;
#pragma omp parallel for
  for(n=0; n<size; ++n)
    table[n] = 0;

  return table[size-1];
}

$ cmake . && make
[...]
Linking C executable tomp
CMakeFiles/tomp.dir/tomp.c.o: In function `main':
tomp.c:(.text+0x87): undefined reference to `GOMP_parallel_start'
tomp.c:(.text+0x98): undefined reference to `GOMP_parallel_end'
CMakeFiles/tomp.dir/tomp.c.o: In function `main._omp_fn.0':
tomp.c:(.text+0xe3): undefined reference to `omp_get_num_threads'
tomp.c:(.text+0xeb): undefined reference to `omp_get_thread_num'
collect2: error: ld returned 1 exit status
make[2]: *** [tomp] Error 1
make[1]: *** [CMakeFiles/tomp.dir/all] Error 2
make: *** [all] Error 2

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-02-09 10:58 Mathieu MalaterreNew Issue                                    
======================================================================



More information about the cmake-developers mailing list