How do I convince cmake (within CLion) I have the OpenMP headers available? I am trying to compile this project SCD and I receive the following error
...
[ 15%] Building CXX object tools/selector/CMakeFiles/selector.dir/source/main.cpp.o
[ 18%] Building CXX object tools/cc/CMakeFiles/cc.dir/source/main.cpp.o
/Users/buddha/github/buddha314/SCD/tools/wcc/source/main.cpp:22:10: fatal error: 'omp.h' file not found
#include <omp.h>
^
The CMakeLists.txt includes
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -pg -fopenmp -DPROFILE ")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -fopenmp -DNDEBUG")
I think that your problem is not specific to CLion but the tool that is used for the building process (i.e CMake) . As already mentioned in this answer, there is a standard module for testing if the compiler supports OpenMP:
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
Related
I have a pretty simple CMake-based project that builds one lib and a small executable that uses it. It builds fine on Linux with GCC, but fails on Mac OS with loads of errors of the following kind. The inciting line of code in main.cpp is the second one here:
#include <cstdlib>
#include <memory>
The first of many similar errors:
[build] In file included from /Users/me/data/series2server/main.cpp:2:
[build] In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/memory:671:
[build] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/c++/v1/__algorithm/search.h:34:19: error: no member named 'make_pair' in namespace 'std::__1'
[build] return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence
This appears to be a mismatch between Clang and GCC uses of std. But I can't figure out why CMake is configuring things to call clang++ but putting "std=gnu++14" in the compiler invocation. I did a full-text search for "std=gnu" in the whole source tree and didn't find it. I do see this in various CMakeLists.txt files:
set( CMAKE_CXX_STANDARD 14 )
A compiler invocation is below. Where might I look for where this gnu option is specified? Thanks!
[build] cd /Users/me/data/series2server/build/restbed && /usr/bin/clang++ -DBUILD_SSL -I/Users/me/data/series2server/restbed/source -isystem /Users/me/data/series2server/restbed/dependency/asio/asio/include -isystem /Users/me/data/series2server/restbed/dependency/openssl/include -Wall -Wextra -Weffc++ -pedantic -Wno-unknown-pragmas -Wno-deprecated-declarations -Wno-non-virtual-dtor -DASIO_STANDALONE=YES -Wno-deprecated-declarations -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -std=gnu++14 -MD -MT restbed/CMakeFiles/restbed-static.dir/source/corvusoft/restbed/detail/service_impl.cpp.o -MF CMakeFiles/restbed-static.dir/source/corvusoft/restbed/detail/service_impl.cpp.o.d -o CMakeFiles/restbed-static.dir/source/corvusoft/restbed/detail/service_impl.cpp.o -c /Users/me/data/series2server/restbed/source/corvusoft/restbed/detail/service_impl.cpp
From n.m.'s comment 10 years ago, for clarity:
set( CMAKE_CXX_STANDARD 14 ) sets gcc or clang flag to -std=gnu++14, unless CXX_EXTENSIONS property (or CMAKE_CXX_EXTENSIONS variable) is set to OFF.
I am fairly new to working with the terminal and I am attempting to use cmake to configure a build for a project that involves public transportation routes. When I attempt to make the build I get the following response in the terminal:
$ cmake ..
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
CMake Warning at CMakeLists.txt:33 (message):
Configuring without OpenMP!
CMake Error at src/CMakeLists.txt:13 (add_subdirectory):
The source directory
/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/src/cppgtfs
does not contain a CMakeLists.txt file.
CMake Error at src/CMakeLists.txt:14 (add_subdirectory):
The source directory
/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/src/configparser
does not contain a CMakeLists.txt file.
-- Configuring incomplete, errors occurred!
See also "/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/build/CMakeFiles/CMakeOutput.log".
See also "/Users/ericbush/Desktop/the-one/toolkit/gtfs/pfaedle/build/CMakeFiles/CMakeError.log".
Below is what I believe to be the relevant code from the CMakeLists.txt file:
find_package(OpenMP)
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# set compiler flags, see http://stackoverflow.com/questions/7724569/debug-vs-release-in-cmake
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "-fopenmp -Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
else()
message(WARNING "Configuring without OpenMP!")
set(CMAKE_CXX_FLAGS "-Ofast -fno-signed-zeros -fno-trapping-math -Wall -Wno-format-extra-args -Wextra -Wformat-nonliteral -Wformat-security -Wformat=2 -Wextra -Wno-implicit-fallthrough -pedantic")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -DLOGLEVEL=3 -DPFAEDLE_DBG=1")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DLOGLEVEL=2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -g -DLOGLEVEL=3")
I have found some similar questions on this and other websites, but I am still struggling to understand the problem because I have never used cmake before and, as mentioned, I am somewhat new to working with the terminal. I would be extremely grateful for any information on what the error messages are actually telling me, or any suggestions on steps I could take/things I could try to solve the issue. I am working on a Mac, if anyone is wondering.
For the compiler to see OpenMP, you may need to set the following options in your cmake command (for dependencies located in /opt/local):
cmake .. \
-DOpenMP_C_FLAGS=-fopenmp=lomp \
-DOpenMP_CXX_FLAGS=-fopenmp=lomp \
-DOpenMP_C_LIB_NAMES="libomp" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_libomp_LIBRARY="/opt/local/lib/libomp.dylib" \
-DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include" \
-DOpenMP_CXX_LIB_NAMES="libomp" \
-DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include"
The two missing CMakeLists.txt are located in git submodules within src/ To download the submodules, cd to the root phaedle directory and issue the following command:
git submodule update --init --recursive
Edit: this is now fixed in master.
I am trying to compile a multi threaded application to WebAssembly. The application uses OpenMP for multithreading.
To compile I am using the Emscripten framework.
I have already downloaded the source files for OpenMP and compiled it for my host machine using make. With the following command I can get it to link with a simple demo application on my machine:
g++ -Wall -Werror -pedantic main.o -o main.x /$PATH_TO_OPENMP/build/runtime/src/libgomp.a -pthread -lstdc++ -Wl,--no-as-needed -ldl
I then tried to compile OpenMP to the llvm bytecode format used by Emscripten. To do so I tried to run 'emmake make', so that the emscripten framework executes the OpenMP makefiles with a suitable compiler. As emscripten does not like shared object files I compiled it to static library .a files.
This works and actually gives me object files to which I can link.
I then wanted to link my demo application with the following command
em++ -Wall -Werror -pedantic main.o -o main.html /home/main/data/Programming/openMP/openmp_web/build/runtime/src/libgomp.a -pthread -lstdc++ -Wl,--no-as-needed -ldl
But I get these warnings, that it couldn't link to OpenMP files:
shared:WARNING: object /tmp/emscripten_temp_ONa0eU_archive_contents/kmp_atomic.cpp.o is not a valid object file for emscripten, cannot link
.
.
shared:WARNING: object /tmp/emscripten_temp_ONa0eU_archive_contents/kmp_str.cpp.o is not a valid object file for emscripten, cannot link
shared:WARNING: object /tmp/emscripten_temp_ONa0eU_archive_contents
So I figured I must have compiled OpenMP with the wrong compiler. I then tried to change the compiler when building the library by using the following commands:
cmake -DCMAKE_C_COMPILER=emcc -DCMAKE_CXX_COMPILER=em++ -DLIBOMP_LIB_TYPE=normal -DLIBOMP_ENABLE_SHARED=OFF -DCMAKE_BUILD_TYPE=Release -DLIBOMP_ARCH=x86_64 OPENMP_STANDALONE_BUILD=1 ..
emmake make
But this just gives strange errors on some missing system variables
/home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_platform.h:82:2: error: Unknown OS
/home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_platform.h:203:2: error: Unknown or unsupported architecture
In file included from /home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_alloc.cpp:13:
In file included from /home/main/data/Programming/openMP/openmp_web/runtime/src/kmp.h:77:
/home/main/data/Programming/openMP/openmp_web/runtime/src/kmp_os.h:171:2: error: "Can't determine size_t printf format specifier."
Does anyone have an idea on what I could do differently?
I would like to generate my android native application with the android NDK and Cmake, so, I've downloaded the android-cmake toolchain.
Cmake generate my project successfully, but when I try to go in the generate directory and try to run "make", I've got the following error:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ldz/Desktop/myProject
[ 1%] Building CXX object Project/src/Main/Core/CMakeFiles/Core.dir/Main/Main.cpp.o
arm-linux-androideabi-g++: error: unrecognized command line option '-stdlib=libc++'
I don't know what is wrong here, my project use C++11, here is my g++ --version result:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
Thanks!
To build an Android NDK project with Cmake and create APK, you should do :
Instead of using android-cmake, you should use the fork from taka-no-me.
Then use Apk.cmake from pixellight. Copy also [AndroidManifest.xml.in, LoadLibraries.java.in, strings.xml.in] from this repo.
Have a CMakeLists.txt like this :
cmake_minimum_required(VERSION 2.8.3)
project(testBuilder)
include("Apk.cmake" REQUIRED)
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
set(TEST_SRC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
src/Main.cpp
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -ffor-scope -fno-rtti -fno-exceptions -pipe -ffunction-sections -fdata-sections -ffast-math -Wnon-virtual-dtor -Wreorder -Wsign-promo -fvisibility=hidden -fvisibility-inlines-hidden -Wstrict-null-sentinel -Os -funroll-all-loops -fpeel-loops -ftree-vectorize")
set(LINKER_FLAGS "${LINKER_FLAGS} -Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined -Wl,--strip-all -Wl,-rpath-link=${ANDROID_NDK_SYSROOT}/usr/lib/ -L${ANDROID_NDK_SYSROOT}/usr/lib/")
add_library(test SHARED ${TEST_SRC})
target_link_libraries(test log android)
set_target_properties(test PROPERTIES COMPILE_DEFINITIONS "ANDROID")
set(APP_SHARED_LIBRARIES ${LIBRARY_OUTPUT_PATH}/libtest.so)
android_create_apk(test "${CMAKE_BINARY_DIR}/apk" "${APP_SHARED_LIBRARIES}" "" "Data")
This is Main.cpp
#include <android_native_app_glue.h>
#include <android/log.h>
#define APPNAME "TestApp"
void android_main(struct android_app* state)
{
app_dummy(); // Make sure glue isn't stripped
__android_log_print(ANDROID_LOG_INFO, APPNAME, "HolyShit you did it !");
ANativeActivity_finish(state->activity);
}
Based on Vi.:s answer I did a clone of android-cmake on github and added a modified Apk.cmake called android.apk.cmake. I use NativeActivity instead of pixellight:s LoadLibraries.java.
The clone is here:
https://github.com/Discordia/android-cmake
I created the example in Vi.:s answer:
https://github.com/Discordia/android-cmake-example
I am using Qt creator 2.5 with CMake (2.8.7) and gcc 4.6.3 and lately I have encountered this strange error :
:-1: error: [CMakeFiles/yahtzee.dir/gamecontroller.cpp.o] Error 1
File not found
What can I do about it ? CMake is not generating this gamecontroller.cpp.o
this is my CMakeLists.txt file
project(cpp_workshop)
cmake_minimum_required(VERSION 2.6)
# Set default compile flags for GCC
if(CMAKE_COMPILER_IS_GNUCXX)
message(STATUS "GCC detected, adding compile flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pedantic -Wall -Wextra -Werror")
else()
message(STATUS "GCC not detected, probably running Windows")
endif(CMAKE_COMPILER_IS_GNUCXX)
#add_definitions("-Wall -Werror")
ADD_DEFINITIONS("-Wno-unused-parameter")
add_executable(yahtzee #name of the executable
gamecontroller.h gamecontroller.cpp
player.h player.cpp
game.h game.cpp
dice.h dice.cpp
strategy.cpp strategy.h
istrategy.h
game_rules.h
main singleton
)
And just to mention, all these files are located in directory and this is the 'build' directory that CMake creates :
CMakeCache.txt CMakeFiles cmake_install.cmake cpp_workshop.cbp Makefile
and the above CMakeFiles dir
CMakeCCompiler.cmake CMakeDirectoryInformation.cmake CompilerIdCXX TargetDirectories.txt
cmake.check_cache CMakeOutput.log Makefile2 yahtzee.dir
CMakeCXXCompiler.cmake CMakeSystem.cmake Makefile.cmake
CMakeDetermineCompilerABI_C.bin CMakeTmp Progress
CMakeDetermineCompilerABI_CXX.bin CompilerIdC progress.marks
Ok, the problem was with Cmake's argument passed to gcc
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
I changed that to
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
and now it works. Surprisingly, C++11 does not work with gcc yet ?