View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0009075CMakeModulespublic2009-05-27 16:462016-06-10 14:30
ReporterTorsten Rohlfing 
Assigned ToBill Hoffman 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionmoved 
PlatformOSOS Version
Product VersionCMake-2-6 
Target VersionFixed in Version 
Summary0009075: FindOpenMP provides required C/CXX flags, not linker flags
DescriptionAccording to CMake's man page section on "FindOpenMP":

The following variables are set:

   OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
   OpenMP_CXX_FLAGS - flags to add to the CXX compiler for OpenMP support
   OPENMP_FOUND - true if openmp is detected

However, to successfully build a binary, one must also activate OpenMP support during the linker stage (otherwise, unresolved symbols remain).

If CMake used the compiler front-end for linking, this could be achieved using the aforementioned C_FLAGS or CXX_FLAGS added to CMAKE_EXE_LINKER_FLAGS, but is there a guarantee that a separate linker, e.g., ld, will always accept the same flag as the compiler?

In a situation where the linker wants different flags for OpenMP support, there does not seem to be a way to completely configure the build using the information detected and provided by FindOpenMP (or the documentation is lacking in this respect).
TagsNo tags attached.
Attached Files

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

  Notes
(0016906)
Philip Lowman (developer)
2009-07-18 02:22

Hello,

I don't know a lot about OpenMP but I have commit access to Modules/ so I can fix any documentation errors at the bare minimum.

So your concern is that FindOpenMP doesn't work on certain compilers because linker flags may need to be added? Which compilers are causing problems?
(0017388)
Bill Hoffman (manager)
2009-09-11 17:28

We did test this with visual studio at some point. What compiler has this issue?
(0017408)
Torsten Rohlfing (reporter)
2009-09-12 04:46

I think I saw this with SunStudio on Linux, but I currently no longer have any systems with this installed, so it will be a while before I can confirm with certainty.
(0021163)
Ian Cullinan (reporter)
2010-06-25 01:41

I'm encountering this at the moment, trying to build a shared library (DLL) using OpenMP with GCC 4.4.0 (MinGW) on Windows. Doing

SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}")

is a workaround for now, but I doubt that that'll work with other toolchains.
(0026548)
Hanspeter Portner (reporter)
2011-05-19 06:28
edited on: 2011-05-19 06:29

I have the same problem with GCC 4.5 on Linux x86 and cmake 2.8.4

gcc apps need to be linked with "-lgomp" (GNU OpenMP utility lib), if not there are undefined references.

when compiled and linked in one go, "-fopenmp" as compile flag is enough, and "-lgomp" is automatically linked in
-> gcc -fopenmp -o myapp myapp.c

but when compiled and linked in two steps (as does CMake), there is the need to either link in "-lgomp" manually or again give the compiler flag "-fopenmp"
-> gcc -fopenmp -c -o myapp.o myapp.c
-> gcc -o myapp myapp.o -lgomp OR gcc -fopenmp -o myapp myapp.o

this hack does the trick for gcc:
-> set_target_properties (myapp PROPERTIES COMPILE_FLAGS ${OpenMP_C_FLAGS})
-> set_target_properties (myapp PROPERTIES LINKER_FLAGS ${OpenMP_C_FLAGS})

but more elegant would be a new output variable ${OpenMP_LD_FLAGS} as output of FindOpenMP which can be set to either "-fopenmp" or "-lgomp" when gcc is detected or else to "" for the other compilers.

and then we could use this:
-> set_target_properties (myapp PROPERTIES COMPILE_FLAGS ${OpenMP_C_FLAGS})
-> set_target_properties (myapp PROPERTIES LINKER_FLAGS ${OpenMP_LD_FLAGS})

possible patch:

*** FindOpenMP.cmake 2011-05-19 12:18:30.000000000 +0200
--- FindOpenMP.cmake.gcc 2011-05-19 12:27:46.000000000 +0200
***************
*** 6,11 ****
--- 6,12 ----
  # The following variables are set:
  # OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
  # OpenMP_CXX_FLAGS - flags to add to the CXX compiler for OpenMP support
+ # OpenMP_LD_FLAGS - flags to add to the linker for OpenMP support
  # OPENMP_FOUND - true if openmp is detected
  #
  # Supported compilers can be found at http://openmp.org/wp/openmp-compilers/ [^]
***************
*** 108,114 ****
--- 109,122 ----
  find_package_handle_standard_args(OpenMP DEFAULT_MSG
    OpenMP_C_FLAGS OpenMP_CXX_FLAGS )
  
+ if (OpenMP_C_FLAGS EQUAL "-fopenmp")
+ set (OpenMP_LD_FLAGS ${OpenMP_C_FLAGS})
+ else
+ set (OpenMP_LD_FLAGS "")
+ end (OpenMP_C_FLAGS EQUAL "-fopenmp")
+
  mark_as_advanced(
    OpenMP_C_FLAGS
    OpenMP_CXX_FLAGS
+ OpenMP_LD_FLAGS
  )

(0041562)
Kitware Robot (administrator)
2016-06-10 14:27

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
2009-05-27 16:46 Torsten Rohlfing New Issue
2009-07-18 02:22 Philip Lowman Note Added: 0016906
2009-07-18 02:22 Philip Lowman Assigned To => Philip Lowman
2009-07-18 02:22 Philip Lowman Status new => assigned
2009-08-29 21:35 Philip Lowman Assigned To Philip Lowman =>
2009-08-29 21:35 Philip Lowman Severity major => feature
2009-08-29 21:35 Philip Lowman Status assigned => new
2009-09-11 17:28 Bill Hoffman Note Added: 0017388
2009-09-11 17:28 Bill Hoffman Status new => assigned
2009-09-11 17:28 Bill Hoffman Assigned To => Bill Hoffman
2009-09-12 04:46 Torsten Rohlfing Note Added: 0017408
2010-06-25 01:41 Ian Cullinan Note Added: 0021163
2011-05-19 06:28 Hanspeter Portner Note Added: 0026548
2011-05-19 06:29 Hanspeter Portner Note Edited: 0026548
2013-10-03 04:27 Matthäus G. Chajdas Note Added: 0033969
2013-10-03 04:32 Matthäus G. Chajdas Note Deleted: 0033969
2015-02-09 11:21 Clinton Stimpson Relationship added related to 0015393
2016-06-10 14:27 Kitware Robot Note Added: 0041562
2016-06-10 14:27 Kitware Robot Status assigned => resolved
2016-06-10 14:27 Kitware Robot Resolution open => moved
2016-06-10 14:30 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team