This question already has answers here:
How to specify a compiler in CMake?
(7 answers)
Closed 3 years ago.
I'm trying to build a simple C++ project on Windows 10 using Clang version 9.0.0. I can run the following command successful.
clang++ main.cpp -o learn.exe
This produces learn.exe which run successful. I need to be able to run something like this.
cmake -G "Clang Makefiles" ..
and then ...
make
As of current CMake, version 3.15 (even 3.16.0-rc3), there is no Clang generator for CMake that I know. Are there CMake generators for Clang or am I missing something?
Selecting the compiler is not done at the generator level, it's done by setting variables to CMake:
cmake -DCMAKE_CXX_COMPILER=clang++ ..
Related
This question already has answers here:
Installing gcc on linux without c compiler
(5 answers)
How install gcc on Linux without compiler
(2 answers)
Closed 9 months ago.
I have a problem that has caused me quite a few headaches and I would like some help from one of you.
I have a Linux operating system installed on my computer. The problem is that it doesn't have the GCC compiler and I would like to build it myself from source code.
The first thing I do is download GCC from its official repository (Latest version)
git clone git://gcc.gnu.org/git/gcc.git
Next, I unzip the GCC .tar.xz package and run the file called configure
At compile time, the process tells me that to compile GCC, I need gawk and bison, and this is where the problem comes.
To install either of those two tools (By source code), I need to have the compiler installed. So it goes like this,
GCC needs GAWK and BISON
GAWK and BISON needs GCC
What could I do?
Thank you!
This question already has answers here:
Running CMake on Windows
(4 answers)
Closed 3 years ago.
I am on Windwos trying to get Mingw-w64 to work with CMake since my MSVC is somehow not working at all (using Windows10 64bit.
Basically I add the arguments -DCMAKE_CXX_COMPILER="C:/MinGW-w64/mingw64/bin/g++.exe" -DCMAKE_C_COMPILER="C:/MinGW-w64/mingw64/bin/gcc.exe" to my call to CMake which sets the corresponding compiler.
However I get these errors:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/MinGW-w64/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
How could I get this to work?
The simplest way to generate makefiles for MinGW (and MinGW-w64) is to use the appropriate CMake generator. Just call cmake with
-G "MinGW Makefiles"
no need to set DCMAKE_CXX_COMPILER and DCMAKE_C_COMPILER by hand.
For this to work, CMake must find your compilers. So this path must be added to the windows PATH variable, as CristiFati pointed out:
C:/MinGW-w64/mingw64/bin
To check if the PATH is correct, fire up a Windows command prompt and run
where gcc
The output should be (at least) the path you just added to the Windows PATH variable.
I am trying to install on my windows desktop, a software suite called NUPACK which is used to design nucleic acid reaction pathways. http://www.nupack.org/
This software requires CMake to install, and from my understanding, CMake does not have compilers by itself, and requires us to have compilers separately installed. As such, I downloaded MinGW to use as a C++ compiler. Prior to running, I have set the environment variables of both CMake and MinGW's bin. I am running CMake (version 3.11.1) through the command prompt but I keep encountering the following problem:
C:\Users\Nicholas\Documents\nupack\build>Cmake -DCMAKE_INSTALL_PREFIX=NUPACKINSTALL -G "MinGW Makefiles" ..
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-
3.11/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/MinGW/bin/gcc.exe"
is not able to compile a simple test program.
I'm guessing CMake cannot identify my MinGW gcc and gcc++ compilers somehow. I tried the following next, but the same error arose.
set CMAKE_C_COMPILER=%C:\mingw\bin\gcc%
set CMAKE_CXX_COMPILER=%C:\mingw\bin\g++%
Has anyone encountered the same problem? Can this be resolved by using MinGW64? I am using Windows 10 and previously, I tried using visual studio 2017's compilers, but it had its on set of problems too.
Yes, the problem is that CMake cannot find GCC compiler. Before be sure that g++ and gcc are installed. It can be MinGW64 or Cygwin.
There are at least three ways to link GCC compiler.
1st way:
Set compilers in CMakeLists.txt:
set(CMAKE_C_COMPILER C:\path\to\gcc.exe)
set(CMAKE_CXX_COMPILER C:\path\to\g++.exe)
2nd way:
When calling cmake in terminal or cmd:
cmake -DCMAKE_C_COMPILER="C:\path\to\gcc.exe" -DCMAKE_CXX_COMPILER="C:\path\to\g++.exe"
3rd way:
Set as environment variable:
Go to Windows "Environment Variables" and add to PATH this:
;C:\path_to_MinGW_or_Cygwin\bin
I had similar problem.
My Setup was : VSCode (Windows 10) + GCC 9.2xx + CMake 3.18.2
Environment variables were already set to point to GCC and CMake.
This Worked: https://stackoverflow.com/a/4101496/2865353
Needs to cleanup CMakeCache.txt and CMakeFiles directory.
Erros it fixed are:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
CMake Error at CMakeLists.txt:3 (project):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
I am using ubuntu 14.04, cmake 2.8.12.2, Qt5.6.2 (a built version), GNU make 3.81
After I run cmake with cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles"
I do make. I get #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
I then download source file of Qt5.7.0, build and install it without problem. I do again cmake PathToSource -G "Eclipse CDT4 - Unix Makefiles", make it. I get many errors, such as /home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qhash.h:957:10: error: ‘pair’ does not name a type
auto pair = qAsConst(*this).equal_range(akey); and /home/sflee/Documents/Software_dev/3rd_party/Qt5.7.0/include/QtCore/qbasicatomic.h:285:14: error: ‘Ops’ has not been declared
{ return Ops::fetchAndAddRelease(_q_value, valueToAdd); }
How to solve it?
Qt 5.7 requires C++11 compiler. If you get that kind of error from auto pair, it sounds like your compiler is not compiling C++11 code. There are two possible reasons:
You just need to pass -std=c++11 to your compiler, as explaned under this question.
You have too old compiler. However, since you compiled Qt 5.7 itself with the same compiler, this shouldn't be the problem for you.
I would like to create an install script for objectiveC with arc and dispatch_queue support for Raspberry Pi. This script will be open sourced in github. Right now lots of the progress is working. But while installing libobjc2 the compiler complains:
error: -fobjc-arc is not supported with fragile abi
I know that I have to set the -fobjc-nonfragile-abi flag to the clang compiler.
Unfortunately I don't know lot about cmake and how to pass arguments to cmake.
This is suggested by GNUstep and works until the error appears:
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
How do I tell cmake using the command line to use the "-fobjc-nonfragile-abi" flag?
You can always append defines like that with SET:
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-nonfragile-abi")
But I haven't use clang, so It's only a guess one