我正在尝试使用C ++使用外部库(特别是OpenCV),但我遇到了一些麻烦。似乎使用VCPKG是解决此问题的最简单方法。到目前为止,我已经遵循了这些教程: https://wwww.youtube.com/watch?v = b7sdgk7y510 和 https://www.youtube.com/www.youtube.com/watch?v=izek3ie5fz3ie5fz3ie5fz0 但是,当我尝试包含一个文件时,我会一直遇到这些错误:
无法开放源文件“ opencv2/core.hpp”
'opencv2/core.hpp'找不到
vscode提供的快速修复的vscode所提供的快速修复,以通过VCPKG,但我已经做到了。我根据教程将VCPKG链接起来,并在我的settings.json文件中包含了CMake工具链文件的路径。
这是我对设置的更改。json文件:
{
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "/Users/oliverpasquesi/coding/dev/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
这是cmakelists.txt文件(与列出的第二个教程中的一个相同):
cmake_minimum_required(VERSION 3.0.0)
project(photoText.cpp VERSION 0.1.0)
add_executable(photoText.cpp main.cpp)
这是c_cpp_properties.json file的includepath部分(包括第二个路径对被抛出的错误没有任何影响):
"includePath": [
"${default}",
"/Users/oliverpasquesi/coding/dev/vcpkg/installed/x64-osx/include/opencv2/**"
]
如果有用,我将在运行Darwin X64 21.5.0的Mac上使用VSCODE 1.49.2。
感谢您的帮助!
I'm trying to use external libraries (specifically opencv) with C++ but I'm having some trouble. It seems like using vcpkg is the easiest way to go about this. So far I've followed these tutorials: https://www.youtube.com/watch?v=b7SdgK7Y510 and https://www.youtube.com/watch?v=iZeK3Ie5Fz0 but I keep getting these errors when I try to include a file:
cannot open source file "opencv2/core.hpp"
'opencv2/core.hpp' file not found
The quick fix provided by vscode says to install opencv through vcpkg but I've already done that. I've linked vcpkg according to the tutorials and included the path to the cmake toolchain file in my settings.json file.
Here is the change I made to my settings.json file:
{
"cmake.configureSettings": {
"CMAKE_TOOLCHAIN_FILE": "/Users/oliverpasquesi/coding/dev/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
}
Here is the CMakeLists.txt file (it is the same as the one from the 2nd tutorial listed):
cmake_minimum_required(VERSION 3.0.0)
project(photoText.cpp VERSION 0.1.0)
add_executable(photoText.cpp main.cpp)
Here is the includePath portion of the c_cpp_properties.json file (including the 2nd path doesn't make any difference in the errors being thrown):
"includePath": [
"${default}",
"/Users/oliverpasquesi/coding/dev/vcpkg/installed/x64-osx/include/opencv2/**"
]
If it's useful, I'm using vscode 1.49.2 on a mac running Darwin x64 21.5.0.
I appreciate the help!
发布评论
评论(1)
您还需要在cmakelists.txt文件中引用库,因为这是CMAKE用来为构建准备项目的文件。
一种现代的方法是添加两行:
当您使用openCV库时,您可能还需要查看此问题的答案:使用cmake 链接openCV
特别是,尝试将这些行添加到您的cmakelists.txt.txt:
vcpkg文档上的cmake Integration(供其他参考): https:///vcppkg.io of cmake-integration.html
希望这会有所帮助!
免责声明:我从事VCPKG工具。
You need to reference your library in the CMakeLists.txt file as well, since that's the file CMake uses to prepare your project for a build.
A modern way to do this is to add two lines:
As you are using the opencv library, you may want to look at the answers to this question as well: Linking Opencv in a project using cmake
Specifically, try adding these lines to your CMakeLists.txt:
vcpkg documentation on its CMake integration (for additional reference): https://vcpkg.io/en/docs/users/buildsystems/cmake-integration.html
Hopefully this helps!
Disclaimer: I work on the vcpkg tool.