1

On a Mac pro I have installed g++

brew install gcc --without-multilib I have then g++-5 installed in /usr/local/bin

The compiler supports OpenMP and also c++11

The following code compiles and runs as expected:

#include <iostream>     
int main(int argc, const char **argv)           
{                  
   auto i = 42;
    int arr[] = {1,2,3,4,5};
    for(int& e : arr) 
    {
          e = e*e;
    }
    #pragma omp parallel                     
    {                          
        std::cout << "Hello OpenMP!\n";         
    }                             
    return 0;                            
}

compiling:

g++-5 -fopenmp -std=c++11 omp_code.cpp -o omp_executable

However,

cmake -DCMAKE_CXX_COMPILER=g++-5 -DCMAKE_C_COMPILER=gcc-5 ..

tells me that Could NOT find OpenMP (missing: OpenMP_CXX_FLAGS)

and The compiler /usr/local/bin/g++-5 has no C++11 support

For OpenMP I use FIND_PACKAGE(OpenMP) and for c++11 I use

include(CheckCXXCompilerFlag)                                        
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

Any idea how to solve this? A workaround was just to put the c++11 and -fopenmp flags even if the checks fail. That worked fine. However, I would like to have a better solution.

Tengis
  • 2,721
  • 10
  • 36
  • 58
  • 1
    Did you scrape the build directory before running `cmake -DCMAKE_CXX_COMPILER=g++-5 -DCMAKE_C_COMPILER=gcc-5 ..` ? This might be the same issue as in http://stackoverflow.com/questions/13851830/cmake-doesnt-honour-d-cmake-cxx-compiler-g – Patrick Jul 23 '15 at 18:00
  • yes. It seems this is it. It works now. – Tengis Jul 25 '15 at 07:05
  • By the way, you can use `set_target_properties(sometarget PROPERTIES CXX_STANDARD 11 CXX_EXTENSIONS FALSE CXX_STANDARD_REQUIRED TRUE)` to get a more robust check for C++11. Requires CMake 3.1+. – Levi Morrison Nov 16 '15 at 17:51

0 Answers0