MantisBT - CMake
View Issue Details
0015393CMake(No Category)public2015-02-09 11:092016-06-10 14:31
Mathieu Malaterre 
Kitware Robot 
normalminorhave not tried
closedmoved 
CMake 3.0.2 
 
0015393: undefined reference to `GOMP_parallel'
This is a follow-up to 0015392. See steps to reproduce.

It make the module hard to use in a portable manner.
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(omp C)
find_package(OpenMP REQUIRED)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
add_library(tomp SHARED tomp.c)
$ cat tomp.c
#include <math.h>

int compute()
{
  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];
}
$ cat toolchain-mingw64.cmake
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)

Then:

$ cmake .. -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw64.cmake
-- The C compiler identification is GNU 4.9.1
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Found OpenMP: -fopenmp
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mathieu/Projects/intranet/junk/omp/bin
$ make VERBOSE=1
/usr/bin/cmake -H/home/mathieu/Projects/intranet/junk/omp -B/home/mathieu/Projects/intranet/junk/omp/bin --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mathieu/Projects/intranet/junk/omp/bin/CMakeFiles /home/mathieu/Projects/intranet/junk/omp/bin/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/mathieu/Projects/intranet/junk/omp/bin'
make -f CMakeFiles/tomp.dir/build.make CMakeFiles/tomp.dir/depend
make[2]: Entering directory '/home/mathieu/Projects/intranet/junk/omp/bin'
cd /home/mathieu/Projects/intranet/junk/omp/bin && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mathieu/Projects/intranet/junk/omp /home/mathieu/Projects/intranet/junk/omp /home/mathieu/Projects/intranet/junk/omp/bin /home/mathieu/Projects/intranet/junk/omp/bin /home/mathieu/Projects/intranet/junk/omp/bin/CMakeFiles/tomp.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/mathieu/Projects/intranet/junk/omp/bin'
make -f CMakeFiles/tomp.dir/build.make CMakeFiles/tomp.dir/build
make[2]: Entering directory '/home/mathieu/Projects/intranet/junk/omp/bin'
/usr/bin/cmake -E cmake_progress_report /home/mathieu/Projects/intranet/junk/omp/bin/CMakeFiles 1
[100%] Building C object CMakeFiles/tomp.dir/tomp.c.obj
/usr/bin/x86_64-w64-mingw32-gcc -Dtomp_EXPORTS -fopenmp -o CMakeFiles/tomp.dir/tomp.c.obj -c /home/mathieu/Projects/intranet/junk/omp/tomp.c
Linking C shared library libtomp.dll
/usr/bin/cmake -E cmake_link_script CMakeFiles/tomp.dir/link.txt --verbose=1
/usr/bin/cmake -E remove -f CMakeFiles/tomp.dir/objects.a
/usr/bin/x86_64-w64-mingw32-ar cr CMakeFiles/tomp.dir/objects.a @CMakeFiles/tomp.dir/objects1.rsp
/usr/bin/x86_64-w64-mingw32-gcc -shared -o libtomp.dll -Wl,--out-implib,libtomp.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles/tomp.dir/objects.a -Wl,--no-whole-archive -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
CMakeFiles/tomp.dir/objects.a(tomp.c.obj):tomp.c:(.text+0xa2): undefined reference to `GOMP_parallel'
CMakeFiles/tomp.dir/objects.a(tomp.c.obj):tomp.c:(.text+0xf1): undefined reference to `omp_get_num_threads'
CMakeFiles/tomp.dir/objects.a(tomp.c.obj):tomp.c:(.text+0xf8): undefined reference to `omp_get_thread_num'
collect2: error: ld returned 1 exit status
CMakeFiles/tomp.dir/build.make:86: recipe for target 'libtomp.dll' failed
make[2]: *** [libtomp.dll] Error 1
make[2]: Leaving directory '/home/mathieu/Projects/intranet/junk/omp/bin'
CMakeFiles/Makefile2:60: recipe for target 'CMakeFiles/tomp.dir/all' failed
make[1]: *** [CMakeFiles/tomp.dir/all] Error 2
make[1]: Leaving directory '/home/mathieu/Projects/intranet/junk/omp/bin'
Makefile:76: recipe for target 'all' failed
make: *** [all] Error 2
No tags attached.
related to 0009075closed Bill Hoffman FindOpenMP provides required C/CXX flags, not linker flags 
related to 0015392closed Kitware Robot Unclear documentation for module: FindOpenMP.cmake 
Issue History
2015-02-09 11:09Mathieu MalaterreNew Issue
2015-02-09 11:21Clinton StimpsonRelationship addedrelated to 0009075
2015-02-10 09:01Brad KingRelationship addedrelated to 0015392
2015-03-16 06:58Alex MerryNote Added: 0038221
2015-03-16 06:59Alex MerryNote Added: 0038222
2015-03-16 07:00Alex MerryNote Deleted: 0038222
2015-03-16 07:01Alex MerryNote Edited: 0038221bug_revision_view_page.php?bugnote_id=38221#r1730
2015-03-16 08:07Alex MerryNote Added: 0038223
2016-06-10 14:29Kitware RobotNote Added: 0042710
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0038221)
Alex Merry   
2015-03-16 06:58   
(edited on: 2015-03-16 07:01)
We've just run into this. What would be useful is a function in FindOpenMP.cmake similar to:

function(openmp_enable _target)
    target_compile_options(${_target}
        PRIVATE
            ${OpenMP_CXX_FLAGS}
    )
    set_property(
        TARGET ${_target}
        APPEND
        PROPERTY LINK_FLAGS
        ${OpenMP_CXX_FLAGS}
    )
endfunction()

but able to deal with other languages (using the LINKER_LANGUAGE property and/or generator expressions to select the correct flags variables).

I would suggest accepting a [PUBLIC|PRIVATE|INTERFACE] option, but there is no INTERFACE_LINK_FLAGS property to set if PUBLIC or INTERFACE are selected (and you can't populate INTERFACE_LINK_LIBRARIES, because "/OpenMP" is not interpreted correctly on Windows, as it doesn't start with "-").

(0038223)
Alex Merry   
2015-03-16 08:07   
Although, note that /openmp is not needed (and is warned about) at link time with MSVC.
(0042710)
Kitware Robot   
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.