简体   繁体   English

在CLION中使用MSYS2安装的库

[英]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. 因此,我一直想学习C ++,我拥有CLion的学生许可证,并且熟悉该公司的其他软件,因此,如果可能的话,我想使用它。 Using MSYS2 seemed like a good way to easily manage libraries, since that tends to be hellish anytime I tried working with C++. 使用MSYS2似乎是轻松管理库的一种好方法,因为在我尝试使用C ++时,这总是让人感到费解。
MSYS2 seemed intuitive enough and I managed to install the OpenCV library as a test. MSYS2似乎足够直观,我设法安装了OpenCV库作为测试。 However, I'm now entirely at a loss on how I'd link it with CLion. 但是,现在我完全不知道如何将其与CLion链接。

I've been reading about CMake files, and this is what I figured should be mine: 我一直在阅读有关CMake文件的信息,而我认为这应该是我的:

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? 我知道MSYS2应该以某种方式处理该问题,或者我应该创建自己的Windows环境变量? 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. 没有人能创造出一种直观的方式来用40年的古老语言在Windows中进行处理。

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 安装MSYS2并按照其网站上的教程( pacman -Syupacman -Su )-您可能已经做到了
  2. pacman -S mingw-w64-x86_64-toolchain (you probably did this too) pacman -S mingw-w64-x86_64-toolchain (您也可能这样做)
  3. pacman -S mingw-w64-x86_64-cmake This is the important step. pacman -S mingw-w64-x86_64-cmake这是重要的步骤。 We will use this CMake instead of the bundled one , because this CMake works with MSYS2 pacman libraries 我们将使用此CMake而不是捆绑的 CMake,因为此CMake可与MSYS2 pacman库一起使用
  4. Configure CLion: MinGW: C:\\msys64\\mingw64 (or similiar), CMake: C:\\msys64\\mingw64\\bin\\cmake.exe 配置CLion:MinGW: C:\\msys64\\mingw64 (或类似),CMake: C:\\msys64\\mingw64\\bin\\cmake.exe
  5. CLion might warn you because CMake/GDB are too new. CLion可能会警告您,因为CMake / GDB太新了。 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. 编辑:实际上,我现在还使用捆绑的CMake对其进行了测试,并且也可以立即使用。 So no idea why it doesn't for you. 所以不知道为什么它不适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM