The simple way is to follow this tutorial created by someone from the CLion team. There is a big chance you will get all the needed help there. You can also try to read this post where someone who has no clue what he is doing will try to set things up in his build environment. You can also try to follow this someone’s approach and write a short article on how to do things because writing is learning. Or was it something with shearing… never mind. Let’s go.
Assumption no. 1 – you have a CLion installed.
Assumption no. 2 – you have a Docker engine running on your machine.
This is our source file (example from imagemagick lib):
#include <Magick++.h>
#include <iostream>
using namespace std;
using namespace Magick;
int main(int argc,char **argv)
{
InitializeMagick(*argv);
Image image;
try {
image.read( "logo:" );
image.crop( Geometry(100,100, 100, 100) );
image.write( "logo.png" );
}
catch( Exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}
This is our cmake config file:
cmake_minimum_required(VERSION 3.10)
project(image_cropper)
find_package(ImageMagick REQUIRED COMPONENTS Magick++)
add_executable(app main.cpp)
include_directories(${ImageMagick_INCLUDE_DIRS})
target_link_libraries(app ${ImageMagick_LIBRARIES})
And this is the error we get when we try to run cmake:
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find ImageMagick (missing: ImageMagick_Magick++_LIBRARY)
Not good. But instead of polluting our machine with the libmagick++-dev package, we will pollute it with a container (package inside). Containers are much easier to clean up, maintain and send to CI when needed. Our Docker config file looks like this:
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -y \
build-essential \
gcc \
g++ \
cmake \
libmagick++-dev \
&& apt-get clean
And we can execute following commands to build our image and the application.
$ docker build -t magic_builder .
$ docker run -v$PWD:/work -it magic_builder /bin/bash
$$ cd work
$$ mkdir build_doker && cd build_doker
$$ cmake .. && make -j 8
So far, so good, but our IDE is sitting in a corner looking sad as we type some shell commands. That is not how it is supposed to be. Come here CLion it is time for you to help us (ears up, tongue out, and it jumps happily into the foreground).
Step 1 Add ssh, rsync and gdb to the image. Also, add an extra user that can be used for opening ssh connection.
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -y \
gdb \
ssh \
rsync \
build-essential \
...
RUN useradd -m user && yes password | passwd user
Step 2 Rebuild and start the container. Check if ssh service is running and start it if not.
$ docker build -t magic_builder .
$ docker run --cap-add sys_ptrace -p127.0.0.1:2222:22 -it magic_builder /bin/bash
$$ service ssh status
* sshd is not running
$$ service ssh start
Step 3 Now go to your IDE settings (Ctrl Alt S), section Build, Execution, Deployment, and add Remote Host toolchain. Add new credentials filling user name, password from Docker file, and port from the run command (2222).

If everything goes well, you should have 3 green checkmarks. Now switch to the new toolchain in your cmake profile (you can also add a separate profile if you want). That’s it. You can build, run and debug using your great CLion IDE. Some improvements are still to be done to our Docker image (auto-start of ssh, running in the background), but all of this is already somewhere on the Internet (same as this instruction but who cares).
You must be logged in to post a comment.