how to get cmake to use the gnu stack of tools under msys2 (mingw) - c++

On Windows 10, with an installed msys2, which is a variant of mingw, I have an installed cmake with the gcc toolchain and all the standard tools like make.
The version of g++ is 6.2 and make is 4.2.1 Both are in the path.
When I build using cmake:
cmake .
it tries to build using nmake and cl. So somehow because I am on windows cmake is trying to use the visual studio toolchain.
export CMAKE_CXX_COMPILER=g++
does not help. The error is:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_87e5f\fast"
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe -- broken
CMake Error at D:/msys64/mingw64/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "D:/msys64/mingw64/bin/clang++.exe" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: D:/git/CSP/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_87e5f\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_87e5f\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "D:/git/CSP/CMakeFiles/CMakeOutput.log".
See also "D:/git/CSP/CMakeFiles/CMakeError.log".

To use MSYS2 toolchain, you need to specify the build system generator explicitly, i.e.
cmake -G 'MSYS Makefiles' .
Additional note, it's a good practice to separate the application . source file and cmake's generated file, e.g.
mkdir build
cd build
cmake -G 'MSYS Makefiles' ..

Related

Conda CMake not finding GCC -- Windows

I'm running a conda environment on Windows to get a bash-similar environment (I'm a native Linux Mint user and this is my first time running Windows). But when I run cmake in my conda environment I get the following error:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:33 (project):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:33 (project):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C://CMakeFiles/CMakeOutput.log".
See also "C://CMakeFiles/CMakeError.log".
CMake Error: Cannot open file for write: C://CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. C://CMakeCache.txt
CMake Error: : System Error: Permission denied
I've installed GCC on my conda environment, but I'm not sure how to force CMake to find it.
UPDATE:
I was able to point the compiler to where gcc is installed, but now I get this error:
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_da93e\fast &&
-- Check for working C compiler: C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe - broken
CMake Error at C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_da93e\fast && The system cannot find the file specified
Generator: execution of make failed. Make command was: nmake /nologo cmTC_da93e\fast &&
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:33 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeError.log".

cmake .. -G Xcode suddenly fails with the project it used to work with

I have a project, where I used to do cmake .. -G Xcode to build for Xcode and it used to work fine. I haven't touched the project for a month or so and when I ran the same command today I got an error below.
The only thing I changed since the last time I built the project was doing some Rust tutorial, so I installed some things for Rust, but I don't remember what exactly.
What could have happened?
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -- broken
CMake Error at /usr/local/Cellar/cmake/3.16.4/share/cmake/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/path-to-project/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_a8107 -configuration Debug -hideShellScriptEnvironment && Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_a8107 -configuration Debug -hideShellScriptEnvironment
User defaults from command line:
HideShellScriptEnvironment = YES
Prepare build
note: The Legacy Build System will be removed in a future release. You can configure the selected build system and this deprecation message in File > Project Settings.
=== BUILD TARGET cmTC_a8107 OF PROJECT CMAKE_TRY_COMPILE WITH CONFIGURATION Debug ===
Check dependencies
No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=arm64 arm64e i386 x86_64, EXCLUDED_ARCHS=(
arm64,
arm64e
)).
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/path-to-project/build/CMakeFiles/CMakeOutput.log".
See also "/Users/path-to-project/build/CMakeFiles/CMakeError.log".
Updating cmake to the latest version (3.18.4) resolved the problem for me.

Can't get CMAKE to compile a project

Here's the error I'm getting:
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_86068\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/--REDACTED--/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_86068\fast"
The system cannot find the file specified
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_86068\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (PROJECT)
-- Configuring incomplete, errors occurred!
See also "C:/--REDACTED--/socket.io-client-cpp-1.6.1/CMakeFiles/CMakeOutput.log".
See also "C:/--REDACTED--/socket.io-client-cpp-1.6.1/CMakeFiles/CMakeError.log".
For the record I am using:
gcc and g++ from MinGW 4.8.1
CMake 3.4.1
I have no idea what the issue could be, I've looked extensively online and have not found anywhere where somebody has gotten a solution, except in cases where it had to do with path issues where the path included non-latin characters or no write access, which is not the case for any of the directories in question. I seriously am about to give up completely on ever being able to get this to work, but I don't know what to do because I absolutely NEED the socket.io client for C++ for this project.
CMake is a utility which generates a "makefile" for different build systems. Here you generate a nmake makefile and it seems that you don't have nmake in your path.
You can launch CMake with option -G "MinGW Makefiles" in order to generate a makefile compatible with mingw make. Then issue the command:
mingw32-make

cmake error showing nonexistent folder on running in cygwin terminal

I am trying to compile a c++ library g2o in cygwin(in windows 8) using cmake . I created a build folder and when I try to do cmake in that folder it fails with the following error
$ cmake ../
-- The C compiler identification is GNU 4.8.3
-- The CXX compiler identification is GNU 4.8.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-2.8.11.2/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/b/g2o/trunk/build/CMakeFiles/CMakeTmp
Run Build Command:/cygdrive/c/Program\
Files/MATLAB/R2009a/bin/win64/gmake.exe "cmTryCompileExec3795381385/fast"
C:/Program Files/MATLAB/R2009a/bin/win64/gmake -f
CMakeFiles/cmTryCompileExec3795381385.dir/build.make
CMakeFiles/cmTryCompileExec3795381385.dir/build
gmake[1]: Entering directory `B:/g2o/trunk/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report "/cygdrive/b/g2o/trunk/build/CMakeFiles/CMakeTmp/CMakeFiles" 1
Building C object
CMakeFiles/cmTryCompileExec3795381385.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTryCompileExec3795381385.dir/testCCompiler.c.o
-c "/cygdrive/b/g2o/trunk/build/CMakeFiles/CMakeTmp/testCCompiler.c"
Linking C executable cmTryCompileExec3795381385.exe
/usr/bin/cmake.exe -E cmake_link_script
CMakeFiles/cmTryCompileExec3795381385.dir/link.txt --verbose=1
gmake[1]: Leaving directory `B:/g2o/trunk/build/CMakeFiles/CMakeTmp'
process_begin: CreateProcess(NULL, /usr/bin/cmake.exe -E cmake_link_script
CMakeFiles/cmTryCompileExec3795381385.dir/link.txt --verbose=1, ...)
failed.
make (e=2): The system cannot find the file specified.
gmake[1]: *** [cmTryCompileExec3795381385.exe] Error 2
gmake: *** [cmTryCompileExec3795381385/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:4 (PROJECT)
-- Configuring incomplete, errors occurred!
The interesting thing here is I have cmake 3.0 installed in my machine and the error says cmake 2.8.11.2. I did a search in the pc and cannot find any folder by that name. The system path variable contains the path to correct cmake bin folder also.
I cannot figure out what could be the reason behind this error. Can it be an issue with the cygwin itself? What can I do to avoid this error?
One thing to note, Cygwin has its own copy of CMake, which is what your seeing as 2.8.11.2. That version has nothing to do with the one you have on your Windows machine. Have you tried to use the Windows installed version and not Cygwin?
I think the problem comes from not having all required compiler libraries installed in Cygwin. You could try creating a simple C++ file and try compiling it with gcc directly. If that fails, you've now found out why CMake is failing.
Unless there is a good reason to do so, you should probably consider NOT using Cygwin to run CMake inside Windows. CMake is very capable of producing Visual Studio project files.
The issue, at least for me, was the c compiler not accepting unix style paths.
The solution was to install gcc via cygwin. The packages I installed is gcc-base and gcc-cpp I believe.

How to build flatbuffers on OSX?

I'm trying to build flatbuffers on OSX but I'm not sure how to proceed exactly. According to the doc. I should run cmake -G "Xcode". I did that and got the result:
-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Check for working C compiler using: Xcode
-- Check for working C compiler using: Xcode -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Xcode
-- Check for working CXX compiler using: Xcode -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: Temp/flatbuffers
However from there I'm not sure what to do. I've tried to run make but got the error message make: *** No targets specified and no makefile found. Stop.. Any idea how to build it?
When you ran cmake, you generated a project for the Xcode IDE (downloadable from the Apple app store).
If you want to build using make, use this command instead:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
After that,
make
should work as intended.
Instead make, just run following command in the shell:
$ cmakexbuild
After it finish you will get flatc in ./Debug folder.
On OSX it's recommended to use Homebrew to install the flatbuffer schema compiler.
brew install flatbuffers
Usage: Using the schema compiler
For Mac-OSX
Make sure Xcode is already installed in your machine. If not, install it by executing command xcode-select --install.
If you need latest changes download source code from repo or to get source code for a particular version download source from here
cd flatbuffers and execute cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release
If you encounter error like
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_CXX_COMPILER could be found.
-- Configuring incomplete, errors occurred!
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeOutput.log".
See also "<sourc-code-path>/flatbuffers-1.12.0/CMakeFiles/CMakeError.log".
Inside the log file CMakeError.log:
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
then refer this SO thread
success message is :
-- Configuring done
-- Generating done
-- Build files have been written to: <source-code-path>/standalone/flatbuffers-1.12.0
./FlatBuffers.xcodeproj or open project in xcode
Build and Run project from Xcode UI
cd Debugand you can see all the binaries present.
If you want flatc to be available globally:
ln -sf <path>/flatbuffers-1.12.0/Debug/flatc /usr/local/bin/flatc
Tried and Tested on
MacOSX: Mojave, version: 10.14.3, 10.14.6
Xcode: Version: 10.2.1(10E1001), 11.1(11A1027)
Note: Make sure you use the same version in a project for compatibility.
If you are not sure which version to pick, then you can clone the repo and go to a specific commit and build.
For e.g. For version 1.11, Commit version is bf9eb67a.
Follow the below steps to compile the flatbuffer code
Clone the Flatbuffer repo using - git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles"
make
FlatBuffers for LINUX(Ubuntu 16) install and build:
cd root project folder
yarn add flatc
cd node_modules of project
rm flatbuffers folder(if exist)
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles" (install cmake if need)
make
cd root project folder
change path in command in package.json file from "./flatc" to "./node_modules/flatbuffers/flatc"