Cmake automatically defaults to gcc-5 - c++

I was trying to compile amber tools using cmake. I am using ubuntu Ubuntu 16.04.7 LTS with the default gcc version gcc-5 and g++5, and amber tool requires at least gcc-6. I have installed gcc-8 and g++8 and specified it using the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. The cmake command used is the command below:
cmake $AMBER_PREFIX/amber22_src \
-DCMAKE_INSTALL_PREFIX=$AMBER_PREFIX/amber22 \
-DCOMPILER=GNU \
-DMPI=FALSE -DCUDA=TRUE -DINSTALL_TESTS=TRUE \
-DDOWNLOAD_MINICONDA=TRUE \
-DCMAKE_C_COMPILER=/usr/bin/gcc-8 -DCMAKE_CXX_COMPILER=/usr/bin/g++-8 \
Even though the gcc g++ is specified I get the following error:
-- Starting configuration of Amber version 22.0.0...
-- CMake Version: 3.14.0
-- For how to use this build system, please read this wiki:
-- http://ambermd.org/pmwiki/pmwiki.php/Main/CMake
-- For a list of important CMake variables, check here:
-- http://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Common-Options
-- **************************************************************************
-- Setting C compiler to gcc
-- Setting CXX compiler to g++
-- Setting Fortran compiler to gfortran
-- Amber source not found, only building AmberTools
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- The Fortran compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- 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/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
--
************************************************************
Error: Amber requires at least g++-6.0
See https://ambermd.org/Installation.php for more info
************************************************************
--
CMake Error at cmake/VerifyCompilerConfig.cmake:30 (message):
Call Stack (most recent call first):
cmake/AmberBuildSystem2ndInit.cmake:30 (include)
CMakeLists.txt:111 (include)
-- Configuring incomplete, errors occurred!
See also "/media/gpu-1/GPU_1_2TB/Ambertools22/amber22_src/build/CMakeFiles/CMakeOutput.log".
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/bin/gcc-8
CMAKE_CXX_COMPILER= /usr/bin/g++-8
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
DOWNLOAD_MINICONDA
MPI
-- Build files have been written to: /media/gpu-1/GPU_1_2TB/Ambertools22/amber22_src/build
If the cmake build report looks OK, you should now do the following:
make install
source /media/gpu-1/GPU_1_2TB/Ambertools22/amber22/amber.sh
Thank you

I would not call it a problem of CMake, rather on the way Amber performs the control of the compiler through CMake, which most likely is performed by taking the first compiler that appears from the environment variable $PATH.
If you would like to compile it anyway, I can suggest two cheap ways:
using the update-alternatives package, to change the "system
default" gcc and g++
prepend a path in PATH with export PATH=absolute/path/to/a/folder:$PATH, and in this path put two symbolic links called gcc and g++, that points at
gcc-8 and g++-8

According to this, you are still using existing cache files that you've generated before you set the new C and CXX compiler.
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/bin/gcc-8
CMAKE_CXX_COMPILER= /usr/bin/g++-8
Based on cmake $AMBER_PREFIX/amber22_src you are running this from your build folder. In general I recommend using the syntax cmake -S[source] -B[build]. Your current working directory should be completely deleted. Once you do that, re-run your cmake command and it should be correctly set.
If it doesn't work you can do a sanity check by adding
set(CMAKE_C_COMPILER [path_to_C])
set(CMAKE_CXX_COMPILER [path_to_CXX])
BE SURE TO PUT IT AT THE START OF THE CMAKELISTS FILE i.e. before any project() line.
EDIT: Also have you heard about docker? It's a great tool for creating special contained environments for using legacy tools.

Related

Cmake Error Compiling Hydrogen 0.9.7 Beta1

I am attempting to compile Hydrogen 0.9.7 beta 2 with Cmake and I keep getting a cmakelists.txt error: CMake Error at CMakeLists.txt:139 (MANDATORY_PKG):
Unknown CMake command "MANDATORY_PKG"
Reviewing the list of Cmake commands I cant find a command that corresponds to MANDATORY_PKG. Is this deprecated language?
Here is the output of the attempted build.
tinman13#tinman13-scythion:~/hydrogen-1.0.0-beta1/build$ sudo cmake /home/tinman13 /hydrogen-1.0.0-beta1/build
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.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
fatal: not a git repository (or any of the parent directories): .git
CMake Error at CMakeLists.txt:138 (INCLUDE):
INCLUDE could not find load file:
StatusSupportOptions
CMake Error at CMakeLists.txt:139 (MANDATORY_PKG):
Unknown CMake command "MANDATORY_PKG".
-- Configuring incomplete, errors occurred!
See also "/home/tinman13/hydrogen-1.0.0-beta1/build/CMakeFiles/CMakeOutput.log".
CMakeOutput.log is a large rambling file but i'll post it if you like.
Is there anything that can be done to rectify this? Can i switch to an older version of CMake? Googling produces very little on the topic of unknown CMake commands and nothing related to Hydrogen. Any help would be greatly appreciated.

Mongodb C++ compilation issue

I am trying to compile mongodb driver for c++ and following instructions given in url : Mongocxx
I am getting below errors :
-- The CXX compiler identification is GNU 4.8.5
-- Check for working CXX compiler: /bin/c++
-- Check for working CXX compiler: /bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The C compiler identification is GNU 4.8.5
-- Check for working C compiler: /bin/cc
-- Check for working C compiler: /bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Checking for module 'libbson-1.0>=1.5.0'
--
CMake Error at /usr/share/cmake3/Modules/FindPkgConfig.cmake:424 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake3/Modules/FindPkgConfig.cmake:597 (_pkg_check_modules_internal)
cmake/FindLibBSON.cmake:33 (pkg_check_modules)
src/bsoncxx/CMakeLists.txt:67 (find_package)
-- Configuring incomplete, errors occurred!
See also "/data/2/nirmal/mongo_cpp/mongo-cxx-
driver/build/CMakeFiles/CMakeOutput.log".
I checked libbson is already installed in /usr/local/bin .
Unable to figure the root cause.
Kindly assist.
If you are building version 3.1.X or 3.0.x you have to specify libbson of your libmongoc (mongodb c driver) installation.
"Users building mongocxx versions 3.1.x and 3.0.x should specify the libmongoc installation directory by using the -DLIBMONGOC_DIR and -DLIBBSON_DIR options to cmake. See the following example, which assumes that both libmongoc and libbson are installed into /your/cdriver/prefix:"
if you are building on a linux system try something like this:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local .. -DBSONCXX_POLY_USE_MNMLSTC=1 -DLIBMONGOC_DIR=/usr -DLIBBSON_DIR=/usr/lib64
More detailed information can be found https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/

CMake can't detect gcc built-in functions such as sqrt, pow ,exp and so on

I just wanna use the CMake to detect whether some built-in functions of GCC exist. So I used the check_function_exists command to do some checking works. Here is my code snippet in CMakeLists.txt.
include (CheckFunctionExists)
set (CMAKE_REQUIRED_INCLUDES math.h)
set (CMAKE_REQUIRED_LIBRARIES m)
check_function_exists(sqrt HAVE_SQRT)
check_function_exists (pow HAVE_POW)
check_function_exists (exp HAVE_EXP)
check_function_exists (log HAVE_LOG)
Code snippet in TutorialConfig.h.in
// the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR #Tutorial_VERSION_MAJOR#
#define Tutorial_VERSION_MINOR #Tutorial_VERSION_MINOR#
#cmakedefine USE_MYMATH
#cmakedefine HAVE_SQRT
#cmakedefine HAVE_POW
#cmakedefine HAVE_LOG
#cmakedefine HAVE_EXP
   However, directory when I executed Cmake command under my source directory. I got such error, weird.
-- The C compiler identification is GNU 7.0.0
-- The CXX compiler identification is GNU 7.0.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
-- Looking for sqrt
CMake Error: The source directory "../build/CMakeFiles/CMakeTmp" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error at /usr/share/cmake/Modules/CheckFunctionExists.cmake:70 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
CMakeLists.txt:23 (check_function_exists)
   However, the directory claimed in the error message is indeed exists.
$ ls -la ../build/CMakeFiles/CMakeTmp
total 0
drwxrwxrwx 1 root root 0 Apr 14 21:41 .
drwxrwxrwx 1 root root 0 Apr 14 20:32 ..
   I am not very expert in CMake, so I can't figure out what is the crux.
   Here is my log file outputed by CMake
Hope anyone who is familiar with CMake gives me a hand. Thanks in advance.
Error message
CMake Error: The source directory "../build/CMakeFiles/CMakeTmp" does not exist.
is possible if a relative path is used as a build directory.
While it is not explicitely stated in docs (and not checked by CMake itself), it is better to use absolute path as build directory.
Because build directory of the CMake project isn't designed to be moved to other place (or even on other machine), there is no reason for using relative path for it.

compiler seems cannot find boost/shared_ptr.hpp

I am using Mac with OS 10.11.6
I am trying to install OpenGV on my Mac. This is a part of dependencies that will be needed to build the OpenSfM library. So, what I did is:
brew install homebrew/science/ceres-solver
brew install boost-python
brew install eigen
git clone https://github.com/paulinus/opengv.git
cd opengv
mkdir build
cd build
cmake .. -DBUILD_TESTS=OFF -DBUILD_PYTHON=ON
make install
But I got this error:
In file included from /Users/hilman_dayo/opengv/src/relative_pose/modules/main.cpp:47:
/Users/hilman_dayo/opengv/include/opengv/math/Sturm.hpp:43:10: fatal error: 'boost/shared_ptr.hpp' file not found
#include <boost/shared_ptr.hpp>
^
1 error generated.
make[2]: *** [CMakeFiles/opengv.dir/src/relative_pose/modules/main.o] Error 1
make[1]: *** [CMakeFiles/opengv.dir/all] Error 2
make: *** [all] Error 2
How can I solve this? Already checked, and the file is there at /usr/local/include/boost/shared_ptr.hpp.
If it is ever needed, this is the output during cmake:
-- The C compiler identification is AppleClang 7.3.0.7030031
-- The CXX compiler identification is AppleClang 7.3.0.7030031
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/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: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for C++11 compiler
-- Checking for C++11 compiler - available
-- Performing Test SUPPORTS_STD_CXX11
-- Performing Test SUPPORTS_STD_CXX11 - Success
-- Performing Test SUPPORTS_STD_CXX01
-- Performing Test SUPPORTS_STD_CXX01 - Success
-- Found Eigen: /usr/local/include/eigen3 (Required is at least version "2.91.0")
CMake Warning at /usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindBoost.cmake:743 (message):
Imported targets not available for Boost version 106200
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindBoost.cmake:842 (_Boost_COMPONENT_DEPENDENCIES)
/usr/local/Cellar/cmake/3.6.3/share/cmake/Modules/FindBoost.cmake:1395 (_Boost_MISSING_DEPENDENCIES)
python/CMakeLists.txt:2 (find_package)
-- Boost version: 1.62.0
-- Found the following Boost libraries:
-- python
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.10")
-- Found PythonInterp: /Users/hilman_dayo/.virtualenvs/cv/bin/python2.7 (found version "2.7.12")
-- Found NumPy: version "1.11.1" /Users/hilman_dayo/.virtualenvs/cv/lib/python2.7/site-packages/numpy/core/include
-- Configuring done
CMake Warning (dev):
Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake
--help-policy CMP0042" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.
MACOSX_RPATH is not specified for the following targets:
pyopengv
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
-- Build files have been written to: /Users/hilman_dayo/opengv/build
OK. Comment by #usr1234567 give me a hint to find the answer. After a quick search, all I need to do is just execute this on the command line:
xcode-select --install

cocos2d-x 3.6 error: Error running command, return code: 1

I have a problem with cocos2d-x 3.6, I installed the program and create my first hello world file found in the program, but when I try to run, I get the following error, someone could tell me how to fix it and explain why it happened the error
cocos run -s ~/MyCompany2/MyGame -p linux
Running command: compile
Building mode: debug
running: 'cmake -DCMAKE_BUILD_TYPE=Debug -DDEBUG_MODE=ON ..'
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- 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/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
It appears you are builing natively for Linux with GCC
-- OpenGL include dirs: /usr/include
-- GLEW include dirs: /usr/include
-- PkgConfig found
-- checking for module 'glfw3'
-- package 'glfw3' not found
CMake Error at cocos2d/cmake/Modules/FindPackageHandleStandardArgs.cmake:136
(message):
Could NOT find GLFW3 (missing: GLFW3_LIBRARIES GLFW3_INCLUDE_DIR)
Call Stack (most recent call first):
cocos2d/cmake/Modules/FindPackageHandleStandardArgs.cmake:343
(_FPHSA_FAILURE_MESSAGE)
cocos2d/cmake/Modules/FindGLFW3.cmake:152
(find_package_handle_standard_args)
cocos2d/cmake/Modules/CocosBuildHelpers.cmake:44 (find_package)
cocos2d/CMakeLists.txt:187 (cocos_find_package)
-- Configuring incomplete, errors occurred!
See also "/home/jmuniz/MyCompany2/MyGame/linux-build/CMakeFile/CMakeOutput.log".
Error running command, return code: 1
The way to read errors in your build chain is typically from the top down; find the first thing marked "error" and fix that.
In this case, the first error is:
CMake Error at cocos2d/cmake/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
Could NOT find GLFW3 (missing: GLFW3_LIBRARIES GLFW3_INCLUDE_DIR)
and right above it the very helpful:
-- package 'glfw3' not found
So, it seems that what you're building requires this glfw3, and it can't find it.
I'm guessing that it's this: http://www.glfw.org/
You should check that you have that. If you don't, download it and install it appropriately for your system (which may, depending on what OS you're running, be as easy as finding it in your package manager), and try again.