Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MSYS2 installed libraries in CLION

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.

like image 422
Fuujin Avatar asked Apr 08 '17 05:04

Fuujin


1 Answers

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.

like image 145
clocktown Avatar answered Sep 21 '22 13:09

clocktown