How to set the environment variables in CMAKE? - cmake

I am trying to use Cmake to manage the dependencies of the Fortran and C code when I compiled the spectral solver. But it seems that Cmake cannot find the compiler although I have downloaded the Fortran and GCC already. This is the error I am getting. I hope there is someone who can tell me how to solve it.
the error screenshot
`CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCompiler.cmake:58 (set_property):
set_property could not find CACHE variable CMAKE_Fortran_COMPILER. Perhaps
it has not yet been created.
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/CMakeDetermineFortranCompiler.cmake:96 (_cmake_find_compiler)
CMakeLists.txt:109 (project)
-- The Fortran compiler identification is unknown
CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCompiler.cmake:58 (set_property):
set_property could not find CACHE variable CMAKE_C_COMPILER. Perhaps it
has not yet been created.
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:65 (_cmake_find_compiler)
CMakeLists.txt:109 (project)
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:109 (project):
No CMAKE_Fortran_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "FC" or the CMake cache entry CMAKE_Fortran_COMPILER to the full
path to the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:109 (project):
No CMAKE_C_COMPILER could be found.
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.`
CMakeLists.txt

You need set the env variables. I used the following steps:
1: vim ~/.bashrc (to set the env variables)
2: Add the following statements
export CC=/usr/bin/gcc (the path basically) and export FC=/usr/bin/gfortran
3 - Also make sure your path to PETSC_DIR and PETSC_ARCH is defined, add the following statements too, export PETSC_DIR = /path/to/petsc and export PETSC_ARCH = gfortran
4 - save and close the file
5 - Run this on command line - to read and execute the bash script source ~/.bashrc

Related

How to install and configure 'cmake' in MSYS2?

How to install and configure 'cmake' in MSYS2?
I have tried installing the following MSYS packages
I am getting the following error on running any cmake commands
'''
CMake Deprecation Warning at CMakeLists.txt:5 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:8 (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:8 (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!
'''
Please help resolve this error.
CMake on Windows tries to use the MSVC compiler by default (cl). To make it use GCC, add following flags: -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++.
You can search for packages on https://packages.msys2.org and find cmake package :
pacman -S cmake

Create Portable CMake/MingGW(G++) [duplicate]

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

LightGBM Installation issue on cmake

I would like to download LightGbm and i followed this website for doing it. But suddenly stopped with an error. Please post a solution.
Thankshttps://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#macos
Error:
cmake ..
CMake Error at /usr/local/Cellar/cmake/3.13.0/share/cmake/Modules/CMakeDetermineCCompiler.cmake:48 (message):
Could not find compiler set in environment variable CC:
gcc-7.
Call Stack (most recent call first):
CMakeLists.txt:7 (PROJECT)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/Users/kj/LightGBM/build/CMakeFiles/CMakeOutput.log".
Your environment variable CC is set to gcc-7 but this compiler can't be access with your $PATH variable.
Try to write gcc-7 in a terminal you should get a Command not found error.

CMake compiler in path not being found

I'm attempting to compile a program using cmake that gives me the following error(s):
CMake Error at /.../3dg.cmake:8 (enable_language):
The CMAKE_CXX_COMPILER:
CC
is not a full path and was not found in the PATH.
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.
Call Stack (most recent call first):
CMakeLists.txt:8 (include)
CMake Error at /.../3dg.cmake:8 (enable_language):
The CMAKE_C_COMPILER:
cc
is not a full path and was not found in the PATH.
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.
I am setting both of these variables in my cmake file with:
set(CMAKE_C_COMPILER cc)
set(CMAKE_CXX_COMPILER CC)
Moreover, I can confirm that both of them are in my path and at the correct location.
>>which cc
/opt/cray/pe/craype/2.5.14/bin/cc
>>which CC
/opt/cray/pe/craype/2.5.14/bin/CC
And my path includes this directory!
>>echo $PATH
/opt/cray/rca/2.2.18-6.0.7.0_33.3__g2aa4f39.ari/bin:/opt/cray/alps/6.6.43-6.0.7.0_26.4__ga796da3.ari/sbin:/opt/cray/job/2.2.3-6.0.7.0_44.1__g6c4e934.ari/bin:/opt/cray/pe/hdf5/1.10.0.3/bin:/opt/cray/pe/craype/2.5.14/bin:/opt/intel/compilers_and_libraries_2018.1.163/linux/bin/intel64:/usr/common/software/metis/5.1.0/bin:/usr/common/software/darshan/3.1.4/bin:/usr/common/software/altd/2.0/bin:/usr/common/software/bin:/usr/common/mss/bin:/usr/common/nsg/bin:/opt/cray/pe/mpt/7.7.0/gni/bin:/opt/ovis/bin:/opt/ovis/sbin:/usr/syscom/nsg/sbin:/usr/syscom/nsg/bin:/opt/cray/pe/modules/3.2.10.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin:/opt/cray/pe/bin:
The cmake file sees the same path as the terminal. I have confirmed that this error goes away if I change my cmake code to:
set(CMAKE_C_COMPILER /opt/cray/pe/craype/2.5.14/bin/cc)
set(CMAKE_CXX_COMPILER /opt/cray/pe/craype/2.5.14/bin/CC)
But this is not a long term fix as the actual location of cc/CC depends on which modules I am using and the updated version of the compilers.
Does anyone know what is going on, and how to force cmake to recognize that these compilers are located in the correct location? Thanks.
Go to download page of glfw and download their source package. Now unzip it and enter into the directory.
Now generate the make file with sudo cmake -G "Unix Makefiles".
Now do sudo make and sudo cmake. The install process should be complete.
For more info take a look at here

Error during building of YAML_CPP with CMake on WIndows

I keep getting an error when I try to build yaml-cpp on Windows.
Using the CMake gui application I selected build- and sourcepath correctly, but as soon as I hit the "Configure" Button there is the following error thrown:
CMake Error: CMake was unable to find a build program corresponding to "**MinGW Makefiles**". **CMAKE_MAKE_PROGRAM** is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/Users/Robert/Programs/Lib/yaml-cpp/build/CMakeFiles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/Users/Robert/Programs/Lib/yaml-cpp/build/CMakeFiles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Configuring incomplete, errors occurred!
I know it has to do with the selected Generator, I selected CodeBlocks - MinGW Makefiles. However I have installed CodeBlocks correctly. So is there perhaps a way to set the CMAKE_MAKE_PROGRAM variable manually?