How to make cmake identify correct version in centos 6 terminal? - cmake

After a very long and lengthy process of trying to get Emscripten going. I'm stuck trying to build fastcomp.
cmake .. -DCMAKE_BUILD_TYPE=Release
-DLLVM_TARGETS_TO_BUILD="X86;JSBackend" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_TESTS=OFF
It gives this error:
CMake Error at cmake/modules/CheckCompilerVersion.cmake:12 (message):
Host GCC version must be at least 4.8!
I've installed devtools 2 and actiavted the toolset.
gcc --version reads as using gcc 4.8.2, but it just won't go.
I've also tried:
export CC=/opt/rh/devtoolset-2/root/usr/bin/gcc
export CXX=/opt/rh/devtoolset-2/root/usr/bin/c++
export CPP=/opt/rh/devtoolset-2/root/usr/bin/cpp
What am I doing wrong?

I had this same problem until I recompiled a recent version of cmake with the newer version of gcc already "activated".
Then, with the CC, CXX and CPP environment variables also set to the appropriate paths, cmake then stopped giving that "Host GCC version must be at least 4.8!" error.

Related

How can I properly tell cmake which CXX compiler to use?

I am trying to build a project from cmake on CentOS 7. The project requires C++ 17 and I'm getting this error from the build:
CMake Error at nvbench/nvbench/CMakeLists.txt:86 (target_compile_features):
target_compile_features The compiler feature "cxx_std_17" is not known to
CXX compiler
"GNU"
version 4.8.5.
L86:
target_compile_features(nvbench PUBLIC cuda_std_17 PRIVATE cxx_std_17)
Naturally, CentOS 7's g++ has version 4.8.5 and doesn't support C++ 17, but I have devtoolset 9 which has g++ version 9.3.1. I've added these lines near the top CMakeLists.txt:
set(CMAKE_C_COMPILER /opt/rh/devtoolset-9/root/bin/gcc)
set(CMAKE_CXX_COMPILER /opt/rh/devtoolset-9/root/bin/g++)
but cmake still references the default compiler and not the one in the devtoolset.
Also made sure to run with scl enable devtoolset-9 'cmake ..' but that didn't work either.
How can I fix this so cmake uses g++ in the devtooset?

CMake -- CUDA compiler is not able to compile a simple test program

I am working on a small library that makes use of CUDA, however I cannot seem to make CMake work when I run it from the command line, even though my IDE (CLion) uses CMake to comile the program succesfully.
I have scoured the internet for ages trying to solve this, though with nothing making much of a difference. I have got CUDA 11.1 and CMake 3.17.3, and both are accessable from the command line.
CLion is able to compile the code perfectly, and everything works as expected, however when I run CMake from the command line, it gives the following error:
PS C:\Users\penci\OneDrive\Desktop\Rapid\Temporary\Rapid\build> cmake ..
-- The CUDA compiler identification is NVIDIA 11.1.105
-- Check for working CUDA compiler: /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin/nvcc.exe
-- Check for working CUDA compiler: /cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin/nvcc.exe - broken
CMake Error at /usr/share/cmake-3.17.3/Modules/CMakeTestCUDACompiler.cmake:46 (message):
The CUDA compiler
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin/nvcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make.exe cmTC_2c864/fast && /usr/bin/make -f CMakeFiles/cmTC_2c864.dir/build.make CMakeFiles/cmTC_2c864.dir/build
make[1]: Entering directory '/cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeTmp'
Building CUDA object CMakeFiles/cmTC_2c864.dir/main.cu.o
"/cygdrive/c/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/bin/nvcc.exe" -forward-unknown-to-host-compiler -x cu -c /cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_2c864.dir/main.cu.o
c1xx: fatal error C1083: Cannot open source file: 'C:/cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeTmp/main.cu': No such file or directory
main.cu
make[1]: *** [CMakeFiles/cmTC_2c864.dir/build.make:86: CMakeFiles/cmTC_2c864.dir/main.cu.o] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:141: cmTC_2c864/fast] Error 2
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 "/cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeOutput.log".
See also "/cygdrive/c/Users/penci/OneDrive/Desktop/Rapid/Temporary/Rapid/build/CMakeFiles/CMakeError.log".
Sorry for the wall of text, but I'm not sure why this doesn't work in the command line, when it does in CLion.
This is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.17)
project(Rapid LANGUAGES CUDA)
set(CMAKE_CUDA_STANDARD 14)
include_directories(${PROJECT_SOURCE_DIR}/include/rapid/graphics/GLFW)
link_directories(${PROJECT_SOURCE_DIR}/include/rapid/graphics/GLFW/lib64)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /openmp")
SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)
add_executable(Rapid main.cu)
set_target_properties(
Rapid
PROPERTIES
CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(Rapid cublas glfw3 gdi32 opengl32)
Any ideas as to how I can fix this issue would be greatly appreciated, as I have spent days trying to fix this, but nothing online seems to work.
After Googling some things that seemed completely unrelated to the issue, I discovered that my Cygwin64 install of CMake was not setup to use Visual Studio generators.
To fix the issue, I needed to put the Visual Studio install of CMake into the PATH environment variable, but it needed to be above the Cygwin64 bin directory. This meant that running the cmake command from the command line would refer to the Visual Studio install, and not the Cygwin64 install, allowing it to work correctly.
Hopefully this helps someone else in the future too

g++ doesn't recognize the file format of a dll

I am on Windows, and I am using the version of g++ that comes with mingw-64. I have a file on my computer called lua51.dll. When I try to run the following command :
g++ -shared -fPIC -o stuff.dll -llua51 stuff.cpp
I get the following error:
C:/Program Files/LOVE/lua51.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
make: *** [main] Error 1
How can I fix this? Please let me know if more information is needed; I am a complete beginner to compilation.
This is an issue you get when you try to include a 64-bit library when running a 32-bit version of g++ or even gcc.
I thought that that the version of g++.exe that comes with mingw-64 would produce 64-bit code, but it turns out this isn't true; it still only produces 32-bit code. In my case, lua51.dll is 64-bit, which is an issue since I was using the version of g++ that produces 32-bit code.
Instead, you need to use x86_64-w64-mingw32-g++.exe, which can be found in the same folder as g++.exe. This is the version of g++ that will produce 64-bit code.

Use LLVM in a cmake build

I'm trying to build my own project that use LLVM. I downloaded the source code and the precompiled package on the official web site (last version).
http://releases.llvm.org/download.html
I downloaded :
LLVM source code
Clang for Windows (64-bit)
FYI, I don't build LLVM... only want to use it !
I followed the instruction here :
http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
in the section : "Embedding LLVM in your project"
So, I added this code :
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message("LLVM_INCLUDE_DIRS=${LLVM_INCLUDE_DIRS}")
message("LLVM_DEFINITIONS=${LLVM_DEFINITIONS}")
But I got several cmake error messages, here is my output :
-- Using LLVMConfig.cmake in: C:\\Luciad_src\\libs\\LLVM\\cmake\\modules
LLVM_INCLUDE_DIRS=
LLVM_DEFINITIONS=
CMake Error at C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:31 (list):
list sub-command REMOVE_ITEM requires two or more arguments.
Call Stack (most recent call first):
C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:256 (is_llvm_target_library)
components/query/CMakeLists.txt:15 (llvm_map_components_to_libnames)
Is there a problem with my script, or the packages I use ? Any idea ?
Thanks for your help
You can have the LLVM as binary or source package.
The binary package does not include CMake support. If you compare both installations (binary on the left, source after building and installing it on the right) you can see the difference:
LLVM-5.0.0-win64.exe
<=> llvm-5.0.1.src.tar.xz (build and installed)
So you need to build and install the source package first to get CMake support. On my Windows machine I needed a cmd shell with administrator rights, a Visual Studio installation, go to the downloaded and extracted sources and do:
> mkdir mybuilddir
> cd mybuilddir
> cmake ..
> cmake --build . --config Release --target INSTALL
If I now use your CMake example I get:
-- Found LLVM 5.0.1
-- Using LLVMConfig.cmake in: C:/Program Files (x86)/LLVM/lib/cmake/llvm
LLVM_INCLUDE_DIRS=C:/Program Files (x86)/LLVM/include
LLVM_DEFINITIONS=-DLLVM_BUILD_GLOBAL_ISEL -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Configuring done

Using libdl.so in MinGW

I want to generate a dll file in MinGW, I have several object dependencies in order to do that, one of my object dependencies is libdl.so, I add this object in unix simply as :
g++ xx.o yy.o /usr/lib/libdl.so -o module.so
but in MinGW, I don't have any idea how to add this object. any ideas?
There is a MinGW port of libdl that you can use just like under Unix. Quote from the website:
This library implements a wrapper for dlfcn, as specified in POSIX and SUS, around the dynamic link library functions found in the Windows API.
It requires MinGW to build.
You may get pre-built binaries (with MinGW gcc 3.4.5) and a bundled source code from the Downloads section.
The following commands build and install it in a standard MinGW installation (to be run from your MinGW shell):
./configure --prefix=/ --libdir=/lib --incdir=/include && make && make install
To compile your library as a DLL, use the following command:
g++ -shared xx.o yy.o -ldl -o module.dll
I encountered the same problem (msys2, 32bit version of compiler etc.).
For me I found out that the libdl.a was available in /usr/lib but not in /mingw32/lib. I was able to solve the problem by linking it to the /mingw32/lib folder:
ln -s /usr/lib/libdl.a /mingw32/lib