5

So I've been wanting to learn C++, I have a student license for CLion and am familiar with other software from the company so I'd want to use it if possible. Using MSYS2 seemed like a good way to easily manage libraries, since that tends to be hellish anytime I tried working with C++.
MSYS2 seemed intuitive enough and I managed to install the OpenCV library as a test. However, I'm now entirely at a loss on how I'd link it with CLion.

I've been reading about CMake files, and this is what I figured should be mine:

cmake_minimum_required(VERSION 3.7)
project(letsee)

set(CMAKE_CXX_STANDARD 11)

find_package (OpenCV REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(letsee ${SOURCE_FILES})
target_link_libraries( letsee ${OpenCV_LIBS} )

The last line, however, is supposed to link to be an environment variable. I understand that MSYS2 should handle that somehow, or perhaps I should create my own windows environment variable? Either way I'm not even sure to where I'd link such variable. I'm just incredibly confused by this point. How can no one have created an intuitive way to handle this in windows in a 40 year old language.

Fuujin
  • 480
  • 5
  • 9
  • 1
    `OpenCV_LIBS` is a CMake variable which should be set by `find_package`. Probably CLion doesn't execute CMake configuration "the right way" with regard to msys2 so it cannot find OpenCV package. – Andrey Turkin Apr 08 '17 at 05:53
  • What do you mean by "MSYS installed" libraries? Do you by any chance install them by executing "configure & make & make install"-like sequence? Your statement about "MSYS being a good way to easily manage libraries" is quite confusing because MSYS has always been exactly the opposite. I'm not sure how clion, cmake and msys are integrated together, but in general it would be a good idea to manually manage all the libraries (probably by keeping them side by side in some kind of "workspace" folder) and rely on installs and envvars as little as possible. – dodo951 Apr 08 '17 at 08:12
  • MSYS2 allows you to use pacman commands to install libraries from a repository. I ran pacman -S *name of library* and it ran and installed. – Fuujin Apr 08 '17 at 14:24
  • Does your build work with the `cmake`command-line interface in a MinGW shell provided by MSYS2? If not, it would be good to debug that first. – David Grayson Apr 08 '17 at 18:06

1 Answers1

13

I just downloaded and setup everything to try it. Here is how it works:

  1. Install MSYS2 and follow the tutorial on their website (pacman -Syu, pacman -Su) - you probably did that already
  2. pacman -S mingw-w64-x86_64-toolchain (you probably did this too)
  3. pacman -S mingw-w64-x86_64-cmake This is the important step. We will use this CMake instead of the bundled one, because this CMake works with MSYS2 pacman libraries
  4. Configure CLion: MinGW: C:\msys64\mingw64 (or similiar), CMake: C:\msys64\mingw64\bin\cmake.exe
  5. CLion might warn you because CMake/GDB are too new. However, I haven't experienced any problems until now

Edit: I actually also tested it with the bundled CMake right now and this worked too, out of the box. So no idea why it doesn't for you.

clocktown
  • 371
  • 1
  • 3
  • 10