CLion on different compilers within one project

Answered

Hey guys!

First off, a shoutout to the great CLion. It's my most favourite tool, period.

I'd like to work with different compilers in one project, as some of the code is accelerated with OpenACC.

Typically, I use the G++/GCC compilers and some MPI stuff. My relatively easy setup in CMakeLists is the following:

cmake_minimum_required(VERSION 3.10)
project(mpi_trials)

# Set C++11 standard
set(CMAKE_CXX_STANDARD 11)

# Find MPI
find_package(MPI REQUIRED)

# Add executables
add_executable(mainExec main.cpp)

# Link against MPI
target_link_libraries(mainExec ${MPI_LIBRARIES})

# Include MPI includes
include_directories(${MPI_INCLUDE_PATH})
if(MPI_COMPILE_FLAGS)
set_target_properties(mainExec PROPERTIES
COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
endif()
if(MPI_LINK_FLAGS)
set_target_properties(mainExec PROPERTIES
LINK_FLAGS "${MPI_LINK_FLAGS}")
endif()

This works great. The IDE finds all the packages/headers/etc. Code highlighting and insight works.

However, I also would like to compile using the PGI tools. To this extent, I added a new Toolchain. A screenshot is attached.

What happens now is that the code insight completely fails.My relatively easy includes just state "file not found":

#include <iostream>
#include <mpi.h>
#include <random>

int main(int argc, char **argv) { ...

I'm not exactly sure how to fix this. Compilation still works, but of course I'd like code insight in my IDE. Is there a step I forgot to apply?

One other relevant thing might be that CMake has some trouble with scanning the compilers. This is the output of re-running CMake on the PGI compilers.

/home/lars/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/183.5153.40/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/home/lars/Applications/pgi/linux86-64/2018/bin/pgcc -DCMAKE_CXX_COMPILER=/home/lars/Applications/pgi/linux86-64/2018/bin/pgc++ -G "CodeBlocks - Unix Makefiles" /home/lars/CLionProjects/mpi_trials
-- The C compiler identification is PGI 18.10.1
-- The CXX compiler identification is PGI 18.10.1
-- Check for working C compiler: /home/lars/Applications/pgi/linux86-64/2018/bin/pgcc
-- Check for working C compiler: /home/lars/Applications/pgi/linux86-64/2018/bin/pgcc -- 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: /home/lars/Applications/pgi/linux86-64/2018/bin/pgc++
-- Check for working CXX compiler: /home/lars/Applications/pgi/linux86-64/2018/bin/pgc++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found MPI_C: /usr/lib/x86_64-linux-gnu/libmpich.so (found version "3.1")
-- Found MPI_CXX: /usr/lib/x86_64-linux-gnu/libmpichcxx.so (found version "3.1")
-- Found MPI: TRUE (found version "3.1")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lars/CLionProjects/mpi_trials/build-release-pgi

Cannot get compiler information:
Compiler exited with error code 2: /home/lars/Applications/pgi/linux86-64/2018/bin/pgc++ -xc++ -I/usr/include/mpich -fast -O3 -DNDEBUG --c++11 --gnu_extensions -fpch-preprocess -v -dD -E
/usr/bin/ld: cannot open linker script file ++: No such file or directory

 

1
2 comments

Hello!

CLion officially supports GCC, Clang and Microsoft Visual C++ compilers. If compiler is GCC-based, CLion usually is also able to work with it (but not guaranteed). Feel free to create a feature request about support of PGI tools in our issue tracker: https://youtrack.jetbrains.com/issues/CPP.

And CLion uses a concept of a project and relies on CMake as a build system for it. All the includes paths, variables and more is taken from CMake files and are used by CLion to understand your project better and to resolve your code correctly. So a CMake project should be successfully loaded so that CLion could provide code insight features.

0
Avatar
Permanently deleted user

Alright, didn't realize it should not necessarily work with every compiler. Thanks for your reply!

0

Please sign in to leave a comment.