I'm using Ubuntu 16.04 x86_64 and LLVM 5.0 and would like to compile a project to a single LLVM IR bitcode file using CMake. I know there is a way to do this using the GOLD Linker with the LLVM Plugin and add the CMake linker flags "-fuse-ld=gold -Wl,-plugin-opt=emit-llvm" and the CXX flag "-flto".
But when I try to compile the project with the LLVM LLD linker and the "-fuse-ld=lld -Wl,-plugin-opt=emit-llvm" respectively "-flto" Flag, the linker is generating a native executable and no LLVM IR file. I was searching for other LLD options to emit a LLVM IR file but found nothing.
Is there a way (or option) to generate a single LLVM IR file using LLD?
You can use the -save-temps option.
clang -flto -fuse-ld=lld -Wl,-save-temps a.o b.o -o myprogram
This will generate myprogramXYZ.precodegen.bc among other files. You can then use llvm-dis to get it in readable IR format.
Related
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?
On my pc I have compiler gcc (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0.
I would like to compile gstreamer source code, where is meson.build.
In meson.build, there is line:
cc = meson.get_compiler('c')
In user's path I set CC to gcc. When I start meson using command:
meson /path/to/directory I see that meson select gcc (gcc 8.1.0 "gcc (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0"). How can I change that?
I tried cc=gcc too.
My cpu is AMD 64bit.
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++.
Attempting to cross-compile with Cmake using a toolchain file I've written for a mips processor. At 22% I get this error:
/usr/local/mipsisa32r2el/r23/bin/ld: cannot find -luuid
Is it LD that is missing a library? Is it possible to rectify when using a mips gcc-compiler?
Did as Tsyvarev said.
git clone https://github.com/karelzak/util-linux.git
Then executed the the autogen.sh to create the configure files.
Finally, ./configure --host=x86_64-unknown-linux-gnu --prefix=$INSTALL_DIR CC=$MIPS_GCC
make
make install
And then copied the lib files to the mips gcc library.
I am linking boost libraries with my .cpp files. The build machine has boost 1.55 in /usr/lib64 and I have boost 1.57 in my local directory. The cmake generates the following link command.
/home/ramki/mpich-install/bin/mpicxx -fopenmp -fexceptions -fno-use-linker-plugin CMakeFiles/factor.dir/factor.cpp.o CMakeFiles/factor.dir/factor_jobs.cpp.o -o factor -rdynamic -lboost_serialization -lboost_iostreams -lboost_program_options -lboost_mpi -llapack -llapacke -lblas -lpthread -lm -lz factorization/libfactorization.a
The above link command does not specify the version of the boost libraries. Because of this I get the following error.
/usr/bin/ld: warning: libboost_serialization.so.1.57.0, needed by /home/ramki/libraries/boost_1_57_0//lib/libboost_mpi.so, may conflict with libboost_serialization.so.1.55.0
Because of this nature of linking, when I use ldd to dump the linked libraries of the executable, I see it linked with couple of libboost 1.55 libraries. If the machine in which I run this executable does not have boost 1.55, it does not start at all.
In the CMakeLists.txt and CMakeCache.txt, I see that the find_package is discovering the 1.57 libraries.
find_package(Boost 1.57.0 COMPONENTS serialization iostreams program_options mpi REQUIRED).
However during linking it is not introducing the version of the library. How do I instruct the cmake to do the following.
linking libraries to use a particular version. For eg., -l:libboost_mpi.so.1.57.0
specify the library path for this version -L library path explicitly. It should NOT link with the library under /usr/lib64.
Ramki
Not sure if this will work for other libraries. Atleast for boost before find_package on boost, set (Boost_REALPATH ON). This will set Boost_LIBRARIES with full path as
/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_serialization.so.1.57.0;/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_iostreams.so.1.57.0;/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_program_options.so.1.57.0;/export5/home/ramki/libraries/boost_1_57_0/lib/libboost_mpi.so.1.57.0.
Use this Boost_LIBRARIES with target_link_libraries(theTarget ${Boost_LIBRARIES}). Thus instead of linking with libboost_mpi.so that could be link to other versions, we are linking with the library of the correct version.