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

 

 

0
3 comments

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.

0

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).

#### From CLion ####
/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
XDG_SESSION_ID=11340
SELINUX_ROLE_REQUESTED=
SHELL=/bin/bash
SSH_CLIENT=::1 37820 22
SELINUX_USE_CURRENT_RANGE=
OLDPWD=/home/XXXX
USER=XXXX
MAIL=/var/mail/XXXX
PATH=/usr/bin:/usr/local/bin:/usr/bin
PWD=/tmp/tmp.WqTFO3FEQO/cmake-build-debug
SELINUX_LEVEL_REQUESTED=
SHLVL=0
HOME=/home/XXXX
LOGNAME=XXXX
SSH_CONNECTION=::1 37820 ::1 22
XDG_RUNTIME_DIR=/run/user/1000
CLION_IDE=TRUE
JETBRAINS_IDE=TRUE
JETBRAINS_REMOTE_RUN=1
CMAKE_COLOR_DIAGNOSTICS=ON
-- 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 XXXXXXXX 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

[Finished]


#### From Terminal (bash) ####
/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
MANPATH=/opt/rh/devtoolset-7/root/usr/share/man::/opt/nvidia/hpc_sdk/Linux_x86_64/21.7/compilers/man:/opt/nvidia/hpc_sdk/Linux_x86_64/21.7/comm_libs/mpi/man
XDG_SESSION_ID=11119
HOSTNAME=XXXX-XXXXX-baremetal
SELINUX_ROLE_REQUESTED=
SHELL=/bin/bash
TERM=xterm-256color
HISTSIZE=1000
SSH_CLIENT=::1 37424 22
PERL5LIB=/opt/rh/devtoolset-7/root//usr/lib64/perl5/vendor_perl:/opt/rh/devtoolset-7/root/usr/lib/perl5:/opt/rh/devtoolset-7/root//usr/share/perl5/vendor_perl:/home/XXXX/perl5/lib/perl5:
SELINUX_USE_CURRENT_RANGE=
QTDIR=/usr/lib64/qt-3.3
PERL_MB_OPT=--install_base /home/XXXX/perl5
QTINC=/usr/lib64/qt-3.3/include
SSH_TTY=/dev/pts/0
X_SCLS=devtoolset-7 
QT_GRAPHICSSYSTEM_CHECKED=1
NVM_DIR=/home/XXXX/.nvm
USER=XXXX
PCP_DIR=/opt/rh/devtoolset-7/root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
LD_LIBRARY_PATH=/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/opt/rh/devtoolset-7/root/usr/lib64/dyninst:/opt/rh/devtoolset-7/root/usr/lib/dyninst:/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/usr/local/cuda/lib64:/usr/local/lib
PATH=/opt/rh/devtoolset-7/root/usr/bin:/usr/lib64/qt-3.3/bin:/home/XXXX/perl5/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/jdk1.8.0_241/bin:/usr/local/cuda/bin:/opt/nvidia/hpc_sdk/Linux_x86_64/21.7/compilers/bin:/opt/nvidia/hpc_sdk/Linux_x86_64/21.7/comm_libs/mpi/bin
MAIL=/var/spool/mail/XXXX
PWD=/tmp/tmp.WqTFO3FEQO/cmake-build-debug
LANG=en_GB.UTF-8
KDEDIRS=/usr
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoreboth
HOME=/home/XXXX
SHLVL=4
PERL_LOCAL_LIB_ROOT=:/home/XXXX/perl5
LOGNAME=XXXX
PYTHONPATH=/opt/rh/devtoolset-7/root/usr/lib64/python2.7/site-packages:/opt/rh/devtoolset-7/root/usr/lib/python2.7/site-packages
QTLIB=/usr/lib64/qt-3.3/lib
SSH_CONNECTION=::1 37424 ::1 22
XDG_DATA_DIRS=/home/XXXX/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share
LESSOPEN=||/usr/bin/lesspipe.sh %s
INFOPATH=/opt/rh/devtoolset-7/root/usr/share/info
XDG_RUNTIME_DIR=/run/user/1000
QT_PLUGIN_PATH=/usr/lib64/kde4/plugins:/usr/lib/kde4/plugins
PERL_MM_OPT=INSTALL_BASE=/home/XXXX/perl5
_=/usr/local/bin/cmake
OLDPWD=/tmp/tmp.WqTFO3FEQO
-- 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-debug

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. 

#### Local (running CLion) ####
uname -a
Linux armstrong 5.15.0-72-generic #79-Ubuntu SMP Tue Apr 18 16:53:43 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"
#### Target (Where compilation should occur) ####
uname -a
Linux XXXX-XXXXX-baremetal 3.10.0-1160.81.1.el7.x86_64 #1 SMP Thu Nov 24 12:21:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release 
Red Hat Enterprise Linux Workstation release 7.9 (Maipo)

Looking forward to your feedback!

 

0

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 ...

0

Please sign in to leave a comment.