Just use the CMakeLists.txt settings and nothing else! [Solved with workaround]
I'm working on a codebase (C++/CUDA) which comes with a working CMakeLists.txt config for my system, (RHEL).
Outside CLion simply:
mkdir build; cd build; cmake..; make
everything just works. When I try to open the project in CLion things start to go wrong. I'm get complaints about ambiguous library paths e.g.:
CMake Warning at gpu_mc/CMakeLists.txt:6 (add_executable):
Cannot generate a safe linker search path for target montecarlosim because
files in some directories may conflict with libraries in implicit
directories:
link library [libgomp.so] in /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7 may be hidden by files in:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5
Some of these libraries may not be found correctly.
and, ignoring those, syntax errors and/complaints about unknown compiler flags. As, I said, outside CLion everything "just works".
So, seems to me that CLion is trying to "help" me my adding a bunch of conflicting items that bork my build. The question:
Is there a way to tell CLion to just run cmake on my CMakeLists.txt in the target build directory and then make -j n and nothing else. I.e. don't do anything, don't touch anything, just what I say and nothing more or less?
EDIT 01.
If I take the cmake and cmake --build commands as emitted within CLion and run them verbatim in a terminal session both succeed without earnings or errors -as expected. What's going on?
See output below, where I copied the commands emitted by CLion and them outside CLion changing only the build directory.
####################
From Terminal (bash)
####################
### Run cmake
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DCMAKE_C_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/gcc -DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++ -DCMAKE_BUILD_TYPE:STRING= -DCMAKE_CODEBLOCKS_EXECUTABLE:FILEPATH= -DCMAKE_CODEBLOCKS_MAKE_ARGUMENTS:STRING= -DCMAKE_CONFIGURATION_TYPES:STRING= -DCUDAToolkit_BIN_DIR:PATH= -G "CodeBlocks - Unix Makefiles" -S /tmp/tmp.WqTFO3FEQO -B /tmp/tmp.WqTFO3FEQO/cmake-build-test
-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/rh/devtoolset-7/root/usr/bin/gcc - 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: /opt/rh/devtoolset-7/root/usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building 64 bit targets
-- CMAKE_GENERATOR Unix Makefiles
-- Found CUDAToolkit: /usr/local/cuda/include (found version "11.6.55")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- The CUDA compiler identification is NVIDIA 11.6.55
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Check for working CUDA compiler: /usr/local/cuda/bin/nvcc - skipped
-- Detecting CUDA compile features
-- Detecting CUDA compile features - done
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/tmp.WqTFO3FEQO/cmake-build-test
### Do build
/usr/local/bin/cmake --build /tmp/tmp.WqTFO3FEQO/cmake-build-test --target notTheRealName -- -j 14
/// chugs along through the objects etc ... ///
[100%] Linking CXX executable ../bin/notTheRealName
[100%] Built target notTheRealName
####################################################################################################################
##########
From CLion
##########
### CMake
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DCMAKE_C_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/gcc -DCMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++ -DCMAKE_BUILD_TYPE:STRING= -DCMAKE_CODEBLOCKS_EXECUTABLE:FILEPATH= -DCMAKE_CODEBLOCKS_MAKE_ARGUMENTS:STRING= -DCMAKE_CONFIGURATION_TYPES:STRING= -DCUDAToolkit_BIN_DIR:PATH= -G "CodeBlocks - Unix Makefiles" -S /tmp/tmp.WqTFO3FEQO -B /tmp/tmp.WqTFO3FEQO/cmake-build-debug
-- Building 64 bit targets
-- CMAKE_GENERATOR Unix Makefiles
-- Configuring done
CMake Warning at gpu_mc/CMakeLists.txt:6 (add_executable):
Cannot generate a safe linker search path for target notTheRealName because
files in some directories may conflict with libraries in implicit
directories:
link library [libgomp.so] in /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7 may be hidden by files in:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5
Some of these libraries may not be found correctly.
-- Generating done
-- Build files have been written to: /tmp/tmp.WqTFO3FEQO/cmake-build-debug
### Build
====================[ Build | notTheRealName | Debug ]===========================
/usr/local/bin/cmake --build /tmp/tmp.WqTFO3FEQO/cmake-build-debug --target notTheRealName -- -j 14
Consolidate compiler generated dependencies of target notTheRealName
/// Chugs along through the objects till it gets to 86% ///
/tmp/tmp.WqTFO3FEQO/common/randomNumbers.cu(7): error: <typeinfo> must be included before typeid is used
/tmp/tmp.WqTFO3FEQO/common/randomNumbers.cu(7): error: <typeinfo> must be included before typeid is used
/tmp/tmp.WqTFO3FEQO/common/randomNumbers.cu(7): error: no operator "==" matches these operands
operand types are: const std::type_info == const std::type_info
/tmp/tmp.WqTFO3FEQO/common/randomNumbers.cu(28): error: <typeinfo> must be included before typeid is used
/tmp/tmp.WqTFO3FEQO/common/randomNumbers.cu(28): error: <typeinfo> must be included before typeid is used
/tmp/tmp.WqTFO3FEQO/common/randomNumbers.cu(28): error: no operator "==" matches these operands
operand types are: const std::type_info == const std::type_info
6 errors detected in the compilation of "/tmp/tmp.WqTFO3FEQO/gpu_mc/main.cu".
make[3]: *** [gpu_mc/CMakeFiles/notTheRealName.dir/main.cu.o] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [gpu_mc/CMakeFiles/notTheRealName.dir/all] Error 2
make[1]: *** [gpu_mc/CMakeFiles/notTheRealName.dir/rule] Error 2
make: *** [notTheRealName] Error 2
Please sign in to leave a comment.
Hi!
Generally, CLion just executes these commands as-is. The possible differences might be:
1. For various reasons, the CMake process in CLion might have a different set of environment variables - could you please verify if it's the case by adding execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment") somewhere in your CMakeLists.txt, and compare its output in both cases?
2. Unlike a shell command, CLion runs CMake without a terminal emulator. You can mimic this behavior along the lines of this post https://superuser.com/a/1430883. However, I never heard if this might cause issues like yours.
Thanks Anna for your reply. Here's the output from running cmake within and outside CLion as before with the additional command you suggested in 1. I'll look at 2. tomorrow, it's getting late where I am.
(Verbatim, except for the XXX's where I masked a couple of things).
For completeness, I should add that I'm doing remote dev. Hereby, some details of those systems, although I don't think it should matter since I use these machines with CLion a lot and haven't run into anything this tricky or annoying before.
Looking forward to your feedback!
There was an obvious solution that I hadn't realized. Just build outside CLion. Unsurprisingly, it turns out that if you build the artifacts where CLion expects to find then you can run and debug as normal which is ultimately what I wanted. It means not clicking the little hammer to build or doing ctrl+F9 but no big deal ...