Why is CMake ignoring the compiler settings via command line? - c++

I am trying to build MAGMA from Windows 10 but it's not working. I downloaded the project MAGMA from here http://icl.utk.edu/projectsfiles/magma/downloads/magma-2.6.2.tar.gz. I downloaded and installed Intel's One API compilers and MKL. I'm taking the following step as part of my command line setup:
> call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
> :: I do this extra because CMake complains that doesn't find the dpcpp and ifort compilers in the PATH.
> set "PATH=%PATH%;C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin"
> set "PATH=%PATH%;C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin\intel64"
in MAGMA project extracted folder I do the typical:
> mkdir build
> cd build
> cmake -DCMAKE_CXX_COMPILER=dpcpp -DCMAKE_Fortran_COMPILER=ifort ..
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- The C compiler identification is MSVC 19.32.31332.0
-- The CXX compiler identification is MSVC 19.32.31332.0
-- The Fortran compiler identification is unknown
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.32.31326/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/2022/BuildTools/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:9 (project):
The CMAKE_Fortran_COMPILER:
ifort
is not a full path and was not found in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/Dev/Opt/magma/2.6.2/build/CMakeFiles/CMakeOutput.log".
See also "C:/Dev/Opt/magma/2.6.2/build/CMakeFiles/CMakeError.log".
UPDATE as shown below, the newest One API C++ compiler dpcpp and ifort are both available in the command line and %PATH% where CMake is run from:
C:\>dpcpp --version
Intel(R) oneAPI DPC++/C++ Compiler 2022.1.0 (2022.1.0.20220316)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm
C:\>ifort --version
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.
ifort: command line warning #10006: ignoring unknown option '/-version'
ifort: command line error: no files specified; for help type "ifort /help"

I'm guessing you're running a version of CMake > 3.0? CMake doesn't necessarily honor the environment paths correctly as it is doing its lookups.
I tried installing 2.8.12.2 (the version recommended by the author) and it seems to build fine.
I also tried with the latest 3.x version (3.22.x) and I see the same error as you do. Rather than try to fix up the CMake file, it might be quicker to just downgrade CMake 2.8.12.x.

Related

"Flow control statements are not properly nested." error while using Cmake for building OpenCV

I am trying to build OpenCV 3.2.0 on my Arch Linux laptop. I got the error when I run cmake.
The cmake command:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
The full output:
CMake Deprecation Warning at CMakeLists.txt:22 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
CMake Deprecation Warning at CMakeLists.txt:72 (cmake_policy):
The OLD behavior for policy CMP0020 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:76 (cmake_policy):
The OLD behavior for policy CMP0022 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
CMake Deprecation Warning at CMakeLists.txt:81 (cmake_policy):
The OLD behavior for policy CMP0026 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
-- The CXX compiler identification is GNU 12.2.1
-- The C compiler identification is GNU 12.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detected version of GNU GCC: 122 (1202)
CMake Error at cmake/OpenCVCompilerOptions.cmake:21 (else):
Flow control statements are not properly nested.
Call Stack (most recent call first):
CMakeLists.txt:495 (include)
-- Configuring incomplete, errors occurred!
Should I need to change Cmake file? I am expecting it shouild work without modifying cmake file or something in code folder.

Build C++20 on mac OS 11

Is this possible? I've been trying for days.
I tried to use homebrew's clang compiler, running this:
cmake -DCMAKE_BUILD_TYPE=Release -S . -B cmake-build-release -Wno-dev -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX
cmake --build ./cmake-build-release --config Release
eventually leads to lipo being called, where it complains:
warning: Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: Invalid value (Producer: 'LLVM15.0.6' Reader: 'LLVM APPLE_1_1300.0.29.3_0')
fatal error: Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't figure out the architecture type of: /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/PluginProcessor-eb9c16/PluginProcessor-arm64.o
I believe lipo is being called because I added this to my cmake project:
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
(This is for a universal build)
I was trying to setup a symlink to point lipo to llvm-lipo but had no luck (and I wasn't sure if this would even fix this error anyway).
If I try to use -G Xcode (the XCode project generator) I get the error:
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: .../Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
CMake Error in cmake-build-xcode/CMakeFiles/CMakeTmp/CMakeLists.txt:
Target "cmTC_e6c65" requires the language dialect "CXXc++2a" (with compiler
extensions). But the current compiler "AppleClang" does not support this,
or CMake does not know the flags to enable it.
I think the best solution would be to somehow get Xcode to use the homebrew Clang compiler - rather than Apple Clang; is this possible?
I was also thinking to overwrite the clang executables included with XCode with symlinks to the HomeBrew clang. This might fix but again seems hackey - when I was trying to setup symlinks to lipo I had to setup weird security stuff / boot mac OS into recovery mode - which is where I gave up

CMake/MinGW unknown compilers, gcc.exe broken

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.

The C++ compiler g++.exe is not able to compile a simple test program - Determining if the CXX compiler works failed

I have been trying to integrate the AWS SDK for C++ into my Netbeans Project. I try to use the cmake command but it fails with the following errors.
Here is the text from running the command in the command prompt
C:\Users\jense\Desktop\code libraries\aws-sdk-cpp-master\aws-sdk-cpp-master>"C:\Users\jense\Desktop\code libraries\cmake-3.8.2-win64-x64\cmake-3.8.2-win64-x64\bin\cmake" .
-- Could NOT find Git (missing: GIT_EXECUTABLE)
-- TARGET_ARCH not specified; inferring host OS to be platform compilation target
-- Building AWS libraries as shared objects
-- Generating windows build config
-- Building project version: 1.1.10
-- The CXX compiler identification is GNU 5.3.0
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_ade23\fast"
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- broken
CMake Error at C:/Users/jense/Desktop/code libraries/cmake-3.8.2-win64-x64/cmake-3.8.2-win64-x64/share/cmake-3.8/Modules/CMakeTestCXXCompiler.cmake:44 (message):
The C++ compiler "C:/MinGW/bin/g++.exe" is not able to compile a simple
test program.
It fails with the following output:
Change Dir: C:/Users/jense/Desktop/code libraries/aws-sdk-cpp-master/aws-sdk-cpp-master/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_ade23\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_ade23\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:105 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/jense/Desktop/code libraries/aws-sdk-cpp-master/aws-sdk-cpp-master/CMakeFiles/CMakeOutput.log".
See also "C:/Users/jense/Desktop/code libraries/aws-sdk-cpp-master/aws-sdk-cpp-master/CMakeFiles/CMakeError.log".
Here is inside my CMakeError.txt
Determining if the CXX compiler works failed with the following output:
Change Dir: C:/Users/jense/Desktop/code libraries/aws-sdk-cpp-master/aws-sdk-cpp-master/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_a5997\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_a5997\fast"
Inside my CMakeOutput.txt
The CXX compiler identification is GNU, found in "C:/Users/jense/Desktop/code libraries/aws-sdk-cpp-master/aws-sdk-cpp-master/CMakeFiles/3.8.2/CompilerIdCXX/a.exe"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/MinGW/bin/g++.exe
Build flags:
Id flags:
The output was:
0
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.exe"
It says that g++ cannot compile a simple test program, however it seems to work fine on my other c++ programs. Also, it instructs me to run nmake /NOLOGO cmTC_a5997\fast. I cannot find nmake installed on my computer, is this the problem? Or is that just another error happening from a chain of errors?
How do I fix this?
I am using Netbeans 8.2 not Visual Studio.
All the answers I have seen on SO don't seem to relate to my issue, they are visual studio related answers and or something fixing a problem that I don't have.
Thanks!
NMake is the traditional make program in the Microsoft toolchain. Since you use MinGW you need mingw32-make, but CMake defaults to the MS toolchain generator on Windows. Call CMake with -G "MinGW Makefiles" to switch to the MinGW generator.
-G "Unix Makefiles", like Miles Budnek suggested in the question’s comments, is the default generator for Unix-like targets. For example, it’s the default on Linux. However, it is not the same as MinGW and won’t work in your situation.
P.S. 1: Especially on Windows make has its problems with using all your CPU cores. You might want to have a look at Ninja. It’s usually a drop-in replacement for make, can be activated with CMake’s -G Ninja and handles parallel builds a lot better.
P.S. 2 (unrelated to the question): Avoid spaces anywhere in your directory paths. Those are a prime source for trouble because you’ll have to quote such paths properly everywhere. That’s (a) suprisingly difficult to get right, (b) something you can easily forget entirely and (c) something all your 3rd-party dependencies’ build systems need to be capable of as well. Not using spaces is the simplest way to avoid all those potential pitfalls.

Windows7 pthread.h not found

I am trying to compile libaws (http://sourceforge.net/projects/libaws/) library in Windows using cmake. I have included openssl, libxml, libcurl and I am using this command line.
C:\libaws>cmake -G "Visual Studio 10" -DCURL_LIBRARY="C:\tools\curl-7.28.1\lib" -DCURL_INCLUDE_DIR="C:\tools\curl-7.28.1\include" -DLIBXML2_LIBRARIES="C:\tools\libxml22.7.8.win32\lib" -DLIBXML2_INCLUDE_DIR="C:\tools\libxml2-2.7.8.win32\include" -DPTHREAD_INCLUDE_DIR="C:\tools\pthread\include" ..\tools\libaws-0.9.2
--
It throws the following error:
-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10
-- Check for working CXX compiler using: Visual Studio 10 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found CURL: C:/tools/curl-7.28.1/lib (found version "7.28.1")
-- Found OpenSSL: optimized;C:/openssl/lib/ssleay32.lib;debug;C:/openssl/lib/ssleay32.lib;optimized;C:/openssl/lib/libeay32.lib;debug;C:/openssl/lib/libeay32.lib (found version "1.0.1c")
-- Found LibXml2: C:/tools/libxml2-2.7.8.win32/lib (found version "2.7.8")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - not found.
CMake Error at CMakeLists.txt:78 (MESSAGE):
Could not find pthread development headers
I have included ptherad.h, semaphore.h etc. in C:\tools\pthread\include, and provided that as a command line flag: -DPTHREAD_INCLUDE_DIR="C:\tools\pthread\include". In my CMakeLists.txt, I added
INCLUDE_DIRECTORIES(${PTHREAD_INCLUDE_DIR})
Any ideas?
Visual Studio doesn't come with a "pthread" implementation. I guess you'll need to use another compiler, like MinGW.
#jens-a-koch is right: my answer should not be accepted! Please "unaccept" so I can remove it.
I belive that your CMake find module might not be using the PTHREAD_INCLUDE_DIR define (similarly to what# drescherjm said).
I had the same error and the solution in short was to install Git for windows!
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
and in CMakeError
checkIncludeFile.c(1,1): fatal error C1083: Cannot open include file: 'pthread.h': No such file or directory
CheckIncludeFile.c(1,1): fatal error C1083: #include <pthread.h>
I already have github app and I used it to clone my project, but for some reason CMake needed Git for windows, so if anyone had this issue this is what worked for me after hours of search