View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015392CMakeCMakepublic2015-02-09 10:582016-06-10 14:31
ReporterMathieu Malaterre 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionmoved 
PlatformOSOS Version
Product VersionCMake 3.0.2 
Target VersionFixed in Version 
Summary0015392: Unclear documentation for module: FindOpenMP.cmake
DescriptionThe 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
TagsNo tags attached.
Attached Files

 Relationships
related to 0015393closedKitware Robot undefined reference to `GOMP_parallel' 

  Notes
(0042709)
Kitware Robot (administrator)
2016-06-10 14:29

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2015-02-09 10:58 Mathieu Malaterre New Issue
2015-02-10 09:01 Brad King Relationship added related to 0015393
2016-06-10 14:29 Kitware Robot Note Added: 0042709
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team