I try to get clang 5.0.0 working for Visual Studio 2015, because I need OpenMP 3.0 features. I installed the clang compiler (not the vs2015 version which does not have any openmp support) and use cmake:
cmake_minimum_required(VERSION 2.8.10)
project(myproject)
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()
include_directories("include")
add_library(libFoo STATIC Foo.cpp)
install(TARGETS Foo libFoo LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
When I now try to configure a MSVC 14 2015 Win64 build with or without toolchain LLVM-vs2014 I always get an error, that OpenMP is not found:
The C compiler identification is Clang 5.0.0
The CXX compiler identification is Clang 5.0.0
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working CXX compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
Configuring done
The used compiler seems to be the right one (Installed clang, not the Microsoft version), it autodetects the clang-cl binary, but OpenMP fails.
I tried to manually specify the compilers with "specify native compilers" and get the same result. It even selects the clang-cl version instead of clang++.
Related Answer, which does not solve the problem:
Compiling C code with openmp using clang-cl - Recent clang has libomp.lib and libiomp5.dll included
It is really a bit tricky and the cmake autodetection doesn't seem to work very well. What helped is
OpenMP_CXX_FLAGS="-Xclang -fopenmp"
OpenMP_C_FLAGS="-Xclang -fopenmp"
And making sure that libomp.lib is in the link libraries.
-Xclang tells the clang binary, that the following options are in clang format and not in MSVC format and -fopenmp is then just the usual OpenMP flag. Setting it any other way did not work, though.
The general pattern is: -Xclang -clangFlag1 -Xclang -clangFlag2.... Namely each Clang Style flag requires its own -Xclang.
Related
I am new in c++
The cmakelist.txt file dont give me a Makefile
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22000.
-- The C compiler identification is MSVC 19.29.30140.0
-- The CXX compiler identification is MSVC 19.29.30140.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/JohnSmith/Documents/Hello/build
I dont know how to change the compiler to G++
this is the cmake
cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
project(HelLo)
add_executable(Hello main.cpp hello.cpp)
I am on windows , Thanks for help
(I can compile with g++ and gcc just cmakefile dont work )
First, make sure you've installed gcc/g++ under Windows (either CygWin or MinGW). Remove the set commands from your CMakelists.txt. Then in a CygWin/MinGW shell use the following command to generate the Makefile:
CC=gcc CXX=c++ cmake ..
cmake -G "Unix Makefiles" ..
I've managed to build a WxWidgets based on CMake on Ubuntu 19.10, but failed on Windows 10, saying that it cannot find WxWidgets, though I've built it successfully (static, release and with unicode support).
WxWidgets path is C:\wxWidgets-3.1.3 and the build directory is C:\wxWidgets-3.1.3\msw-release.
The makefile is
cmake_minimum_required(VERSION 3.0)
project(ChessPgnReviser VERSION 0.1.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
ADD_DEFINITIONS(-Wall -Wno-sign-compare -O2)
set(SRCS
src/main.cpp
)
set (HEADERS
)
message( "--Root--" ${wxWidgets_ROOT_DIR} )
message( "--Lib dir--" ${wxWidgets_LIB_DIR} )
add_executable(ChessPgnReviser ${SRCS} ${HEADERS})
find_package(wxWidgets COMPONENTS net gl core base)
if(wxWidgets_FOUND)
include(${wxWidgets_USE_FILE})
target_link_libraries(ChessPgnReviser ${wxWidgets_LIBRARIES})
else()
message(FATAL_ERROR "Failed to find WxWidgets library")
endif()
I'm using Msys 64 bit in order to compile the project. At the bottom of its subfolder etc/profile, I've added
PATH=$PATH:/c/dev/cmake/bin
wxWidgets_ROOT_DIR=/c/wxWidgets-3.1.3
wxWidgets_LIBRARIES=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_LIB_DIR=$wxWidgets_ROOT_DIR/msw-release/lib
wxWidgets_INCLUDE_DIRS=$wxWidgets_ROOT_DIR/include
So I've tried
$ mkdir build && cd build
$ cmake .. -G "MinGW Makefiles"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--
--Lib dir--
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
Also, thanks to #squareskittles, I also tried:
$ cmake .. -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR="C:\wxWidgets-3.1.3" -DwxWidgets_LIB_DIR="C:\wxWidgets-3.1.3\msw-release\lib"
-- The C compiler identification is GNU 10.1.0
-- The CXX compiler identification is GNU 10.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--Root--C:\wxWidgets-3.1.3
--Lib dir--C:\wxWidgets-3.1.3\msw-release\lib
-- Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS net gl core base)
CMake Error at CMakeLists.txt:27 (message):
Failed to find WxWidgets library
-- Configuring incomplete, errors occurred!
See also "C:/Users/laure/Documents/Programmation/ProjetsPersos/Cpp/ChessPgnReviserWxWidgets/build/CMakeFiles/CMakeOutput.log".
You can find the content of the msw-release folder : there.
Also:
$ ls /c/wxWidgets-3.1.3/msw-release/lib/
libwx_baseu_net-3.1.a libwx_baseu-3.1.a libwx_mswu_aui-3.1.a libwx_mswu_gl-3.1.a libwx_mswu_media-3.1.a libwx_mswu_qa-3.1.a libwx_mswu_richtext-3.1.a libwx_mswu_webview-3.1.a libwxregexu-3.1.a wx
libwx_baseu_xml-3.1.a libwx_mswu_adv-3.1.a libwx_mswu_core-3.1.a libwx_mswu_html-3.1.a libwx_mswu_propgrid-3.1.a libwx_mswu_ribbon-3.1.a libwx_mswu_stc-3.1.a libwx_mswu_xrc-3.1.a libwxscintilla-3.1.a
So did I forget something ?
To properly detect wxWidgets you need wx-config.
A Windows version of wx-config exists and can be downloaded from: https://github.com/kowey/wx-config-win
To make wx-config know where your wxWidgets is, you need set the following environment variables:
WXWIN (in your case to C:/wxWidgets-3.1.3)
WXCFG (in your case to something like msw/gcc_mswu).
According to https://blog.kitware.com/cmake-finding-qt5-the-right-way/, the method find_package(Qt5 COMPONENTS Core Qml Quick Svg Qt5WebSockets REQUIRED) allows me to load lots of QT5 packages while being able to set the QT root only once by setting the Qt5_DIR variable. I'm trying to compile a minimal CMake project which is listed below, using this technique. You can see that WebSockets isn't found. What is the problem?
PS: My home directory at /home/lz/Qt5.11.2 indeed has a new Qt installation that Qt installer just installed for me, and it indeed has libwebsockets and websocket include files.
My CMakeLists.txt:
find_package(Qt5 COMPONENTS Core Qml Quick Svg Qt5WebSockets REQUIRED)
How do I run it:
cmake -DQt5_DIR=/home/lz/Qt5.11.2 .
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/lib/x86_64-linux-gnu/cmake/Qt5/Qt5Config.cmake:28 (find_package):
Could not find a package configuration file provided by "Qt5Qt5WebSockets"
with any of the following names:
Qt5Qt5WebSocketsConfig.cmake
qt5qt5websockets-config.cmake
Add the installation prefix of "Qt5Qt5WebSockets" to CMAKE_PREFIX_PATH or
set "Qt5Qt5WebSockets_DIR" to a directory containing one of the above
files. If "Qt5Qt5WebSockets" provides a separate development package or
SDK, be sure it has been installed.
Call Stack (most recent call first):
CMakeLists.txt:1 (find_package)
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.9)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
See also "/home/lz/c/CMakeFiles/CMakeOutput.log".
PS: without WebSockets cmake 'compiles' just fine, so the WebSockets is the only module not found
UPDATE:
After the help below, I'm still having an error related to WebSocket:
/home/lz/orwell/react-native-desktop-orwell/ReactQt/runtime/src/websocketmodule.cpp:12:10: fatal error: QWebSocket: No such file or directory
#include <QWebSocket>
and now I'm successfully using my QT, as you can see in the verbose output:
[ 50%] Building CXX object CMakeFiles/m.dir/main.o
/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include/QtWidgets -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include/QtGui -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/include/QtCore -isystem /home/lz/Qt5.11.2/5.11.2/gcc_64/./mkspecs/linux-g++ -fPIC -std=gnu++11 -o CMakeFiles/m.dir/main.o -c /home/lz/c/main.cpp
/home/lz/c/main.cpp:1:10: fatal error: QWebSocket: No such file or directory
#include <QWebSocket>
^~~~~~~~~~~~
compilation terminated.
Change the line in your CMakeLists.txt to
find_package(Qt5 COMPONENTS Core Qml Quick Svg WebSockets REQUIRED)
You don't need to add "Qt5" prefix to the name of the component using this syntax.
For me fixed after installing libqt5websockets5-dev:
sudo apt install libqt5websockets5-dev
On Windows 10 with VS2017 and LLVM installed
and CMAKE just takes VC compiler as default and ignores both set command in the CMakeLists.txt and command line -DCMAKE_CXX_COMPILER
I have no idea how to make it use LLVM Clang
I checked out many existing questions but they do not work for me
CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
set(CMAKE_CXX_COMPILER "C:\\Program Files\\LLVM\\bin\\Clang++")
project(CMakeTest1 VERSION 0.0.0 LANGUAGES CXX)
aux_source_directory(. MAINDIR)
add_executable(CMakeTest1 ${MAINDIR})
main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
running command with git bash
***#DESKTOP-8KJ4J0H MINGW64 /d/CMakeTest1
$ cmake -DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\Clang++" .
-- Building for: Visual Studio 15 2017
-- The CXX compiler identification is MSVC 19.13.26129.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/CMakeTest1
my CXX compiler identification is forced to be MSVC and cannot be changed by any method.
no idea why
EDITED:
what i wanna strongly declare is, i swear and clearly know that i CLEANED ALL GENERATED FILES form the folder and there are ONLY JUST CMakeLists.txt and main.cpp existing. and I DON'T WANT TO BE ASSUMED having old cache files unremoved
This may be due to default generator of CMake in Windows.
-- Building for: Visual Studio 15 2017
...
You can change the generator by adding -G <generator name> to the command line. In your case, I think -G 'MSYS Makefiles' may work.
This happens because CMAKE_CXX_COMPILER was inferred from your generator (The latest Visual Studio is used by default on windows), so it is cl.exe.
In order to switch to clang you should use other generator e.g. Ninja or Unix Makefiles.
If you want to use VS with clang-cl.exe, you need to set platform toolset to appropriate version by adding flag -TLLVM-vs2014.
See this instructions for more info.
I have compiled Boost 1.51.0 on Windows using the rubenvb's CLang build. I actually compiled b2 using MinGW:
bootstrap mingw
... compiling b2 using mingw...
and then I compiled the libraries with CLang:
b2 toolset=clang stage --stagedir=. --build-type=complete --with-regex ...
By the way, even if I specified --build-type=complete there are no DLLs in lib directory, but I read somewhere that CLang has still problem with linking on Windows so that might be the reason. Anyway static libraries are fine for me. I got these files in %BOOST_ROOT%\lib:
libboost_regex-clang31-1_51.lib
libboost_regex-clang31-d-1_51.lib
libboost_regex-clang31-mt-1_51.lib
libboost_regex-clang31-mt-d-1_51.lib
libboost_regex-clang31-mt-s-1_51.lib
libboost_regex-clang31-mt-sd-1_51.lib
libboost_regex-clang31-s-1_51.lib
libboost_regex-clang31-sd-1_51.lib
Now, if I compile something with CLang from command line everything works. The problem shows when I try to make CMake find Boost libraries: it simply could not find them. I tried with this CMakeFiles.txt:
cmake_minimum_required (VERSION 2.8)
project(ccc)
# Setting/unsetting this does not change anything.
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS regex REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(ccc main.cpp)
target_link_libraries(ccc
${Boost_REGEX_LIBRARY}
)
Building it using MinGW (and a MinGW compiled version of Boost) it works. If I try with CLang (after having setted CC=clang, CXX=clang++ and BOOST_ROOT=C:/misc/boost/clang-1_51_0) it does not:
D:\Desktop\ppp>cmake -G "MinGW Makefiles" ..\ccc
-- The C compiler identification is Clang 3.1.0
-- The CXX compiler identification is Clang 3.1.0
-- Check for working C compiler: C:/misc/clang/bin/clang.exe
-- Check for working C compiler: C:/misc/clang/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake:1191 (message):
Unable to find the requested Boost libraries.
Boost version: 1.51.0
Boost include path: C:/misc/boost/clang-1_51_0
The following Boost libraries could not be found:
boost_regex
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
CMakeLists.txt:5 (find_package)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_REGEX_LIBRARY (ADVANCED)
linked by target "ccc" in directory D:/Desktop/ccc
-- Configuring incomplete, errors occurred!
However, if I compile manually it works again:
clang++ main.cpp -I%BOOST_ROOT% -L%BOOST_ROOT%\lib -llibboost_regex-clang31-1_51
...Ok, and the executable works
Manually setting BOOST_LIBRARYDIR does not work either. Neither does using backslashes \.
Looking inside the file "C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake" you can find a list of all the variables related to Boost you can use. The one you need is Boost_COMPILER (Boost_DETAILED_FAILURE_MSG can also be useful to diagnose problems):
# Boost_COMPILER Set this to the compiler suffix used by Boost
# (e.g. "-gcc43") if FindBoost has problems finding
# the proper Boost installation