find opencv failed in vcpkg
Xmake 版本
2.7.1
操作系统版本和架构
win10 amd64 21h2
描述问题
xmake安装opencv的时候报错
期待的结果
xmake安装opencv的时候报错
工程配置
add_rules("mode.debug", "mode.release") add_requires("vcpkg::opencv")
target("CamScanner") add_packages("vcpkg::opencv") set_kind("binary") add_files("src/*.cpp")
附加信息和错误日志
xmake f -c -v
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for dmd ... no
checking for ldc2 ... no
checking for gdc ... no
checking for zig ... no
checking for zig ... no
checking for unzip ... no
checking for 7z ... C:\Program Files\xmake\winenv\bin\7z
checking for git ... ok
checking for gzip ... no
checking for vcpkg::opencv ... no
note: install or modify (m) these packages (pass -y to skip confirm)?
in vcpkg:
-> vcpkg::opencv latest [vs_runtime:"MT"]
please input: y (y/n/m)
y
checking for vcpkg ... no
error: vcpkg not found!
=> install vcpkg::opencv latest .. failed
error: ...mdir\core\sandbox\modules\import\core\base\scheduler.lua:56: install failed!
stack traceback:
@programdir\core\base\utils.lua:290: in function <@programdir\core\base\utils.lua:280>
[C]: in function 'error'
@programdir\core\base\os.lua:882: in function 'os.raiselevel'
(...tail calls...)
...mdir\core\sandbox\modules\import\core\base\scheduler.lua:56: in field 'co_start_withopt'
@programdir\modules\private\async\runjobs.lua:217: in function <@programdir\modules\private\async\runjobs.lua:162>
[C]: in function 'xpcall'
@programdir\core\base\utils.lua:280: in function 'sandbox/modules/utils.trycall'
@programdir\core\base\scheduler.lua:504: in function 'base/scheduler.co_group_begin'
...mdir\core\sandbox\modules\import\core\base\scheduler.lua:94: in field 'co_group_begin'
@programdir\modules\private\async\runjobs.lua:162: in function <@programdir\modules\private\async\runjobs.lua:56>
(...tail calls...)
...modules\private\action\require\impl\install_packages.lua:395: in global '_install_packages'
...modules\private\action\require\impl\install_packages.lua:777: in function <...modules\private\action\require\impl\install_packages.lua:648>
(...tail calls...)
@programdir\modules\private\action\require\install.lua:85: in function <@programdir\modules\private\action\require\install.lua:61>
(...tail calls...)
@programdir\actions\config\main.lua:424: in function <@programdir\actions\config\main.lua:254>
(...tail calls...)
[C]: in function 'xpcall'
@programdir\core\base\utils.lua:280: in function 'sandbox/modules/utils.trycall'
(...tail calls...)
@programdir\core\base\task.lua:501: in function 'base/task.run'
@programdir\core\main.lua:278: in upvalue 'cotask'
@programdir\core\base\scheduler.lua:388: in function <@programdir\core\base\scheduler.lua:385>
error: vcpkg not found!
错误不是很明显么,vcpkg 没找到,通过 xmake g --vcpkg=/xxx 或者 xmake f --vcpkg= 设置下
或者设置下 VCPKG_ROOT
另外,有 xmake-repo 自带 opencv 包干嘛不用,add_requires("opencv")
sry 脑瘫了没看到这个,只看到了下面那个error
xmake f -c -v checking for platform ... windows checking for architecture ... x64 checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64\cl.exe checking for Microsoft Visual Studio (x64) version ... 2022 checking for dmd ... no checking for ldc2 ... no checking for gdc ... no checking for zig ... no checking for zig ... no checking for unzip ... no checking for 7z ... C:\Program Files\xmake\winenv\bin\7z checking for git ... ok checking for gzip ... no checking for vcpkg::opencv ... no note: install or modify (m) these packages (pass -y to skip confirm)? in vcpkg: -> vcpkg::opencv latest [vs_runtime:"MT"] please input: y (y/n/m) y checking for vcpkg ... C:\dev\vcpkg\vcpkg C:\dev\vcpkg\vcpkg install opencv:x64-windows-static Computing installation plan... The following packages are already installed: opencv[core,default-features]:x64-windows-static -> 4.6.0 opencv:x64-windows-static is already installed Restored 0 package(s) from C:\Users\share\AppData\Local\vcpkg\archives in 249.3 us. Use --debug to see more details.
Total elapsed time: 11.82 ms
opencv provides CMake targets:
# this is heuristically generated, and may not be correct
find_package(OpenCV CONFIG REQUIRED)
# note: 13 additional targets are not displayed.
target_link_libraries(main PRIVATE opencv_ml opencv_dnn opencv_core opencv_flann)
checking for vcpkg::opencv ... no
error: fetch vcpkg::opencv-latest failed! => install vcpkg::opencv latest .. failed error: install failed!
他这个不是现实我已经安装了,为什么还是失败 The following packages are already installed: opencv[core,default-features]:x64-windows-static -> 4.6.0
error: fetch vcpkg::opencv-latest failed!
fetch 包失败,装完没找到库文件,自己 https://github.com/xmake-io/xmake/blob/master/xmake/modules/package/manager/vcpkg/find_package.lua 里面加 print 调下。。
或者用 add_requires("opencv")
vcpkg是不是最好加一个cmake的find_package?vcpkg官方推荐也是从cmake引入,就是要手动设置opencv_ml opencv_dnn opencv_core opencv_flann 这些target稍微麻烦点
vcpkg是不是最好加一个cmake的find_package?vcpkg官方推荐也是从cmake引入,就是要手动设置opencv_ml opencv_dnn opencv_core opencv_flann 这些target稍微麻烦点
如果它的 info list 里面带了 cmake 文件,是可以通过 cmake find 来改进查找的,只是之前一直没空弄,还有 pacman 包也是目前仅支持从 pkgconfig找
从 cmake 找不太好搞
这个包 info list 里面就这些
/tmp/vcpkg/installed/vcpkg/info/opencv_4.6.0_x64-linux.list
x64-linux/
x64-linux/share/
x64-linux/share/opencv/
x64-linux/share/opencv/OpenCVConfig-version.cmake
x64-linux/share/opencv/OpenCVConfig.cmake
x64-linux/share/opencv/OpenCVModules-debug.cmake
x64-linux/share/opencv/OpenCVModules-release.cmake
x64-linux/share/opencv/OpenCVModules.cmake
x64-linux/share/opencv/vcpkg.spdx.json
x64-linux/share/opencv/vcpkg_abi_info.txt
直接找,缺 Protobuf,不知道在哪,感觉没 pkg-config 找起来方便可靠
$ CMAKE_PREFIX_PATH=/tmp/vcpkg/packages/opencv_x64-linux/share/opencv xmake l -vD find_package cmake::OpenCV
running builtin module find_package with args:
dump from _print_vlog @@programdir/plugins/lua/main.lua:55
"cmake::OpenCV"
finding OpenCV from cmake ..
checking for cmake ... /usr/bin/cmake
/usr/bin/cmake /dev/shm/.xmake999/220930/_40E6988129354B208EA32D16C784CB30.dir
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /tmp/vcpkg/packages/opencv_x64-linux/share/opencv/OpenCVConfig.cmake:116 (message):
OpenCV: Include directory doesn't exist:
'/tmp/vcpkg/packages/opencv_x64-linux/include'. OpenCV installation may be
broken. Skip...
Call Stack (most recent call first):
CMakeLists.txt:3 (find_package)
CMake Error at /usr/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
Could not find a package configuration file provided by "Protobuf" with any
of the following names:
ProtobufConfig.cmake
protobuf-config.cmake
Add the installation prefix of "Protobuf" to CMAKE_PREFIX_PATH or set
"Protobuf_DIR" to a directory containing one of the above files. If
"Protobuf" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
/tmp/vcpkg/packages/opencv_x64-linux/share/opencv/OpenCVModules.cmake:20 (find_dependency)
/tmp/vcpkg/packages/opencv_x64-linux/share/opencv/OpenCVConfig.cmake:126 (include)
CMakeLists.txt:3 (find_package)
所以还不如直接用 xmake-repo 里面的 opencv
要用vcpkg的包需要加一个-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake,不设置toolchain会有问题,只加一个config大概率不行
要用vcpkg的包需要加一个-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake,不设置toolchain会有问题,只加一个config大概率不行
什么问题
要用vcpkg的包需要加一个-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake,不设置toolchain会有问题,只加一个config大概率不行
什么问题
例如找不到protobuf,加了toolchain就可以找到vcpkg的其他依赖包
要用vcpkg的包需要加一个-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake,不设置toolchain会有问题,只加一个config大概率不行
什么问题
例如找不到protobuf,加了toolchain就可以找到vcpkg的其他依赖包
试了下,这样确实不报错了,但是没有 opencv 的 links
$ CMAKE_TOOLCHAIN_FILE=/tmp/vcpkg/scripts/buildsystems/vcpkg.cmake xmake l find_package cmake::OpenCV
{
links = {
"dl",
"m",
"pthread",
"rt"
},
includedirs = {
"/tmp/vcpkg/installed/x64-linux/include"
}
}
我看装完 opencv 有提示,还得额外手动配 link?
# this is heuristically generated, and may not be correct
find_package(OpenCV CONFIG REQUIRED)
# note: 11 additional targets are not displayed.
target_link_libraries(main PRIVATE opencv_ml opencv_dnn opencv_core opencv_flann)
是的,要手动设置link
是的,要手动设置link
那就比较蛋疼了,这样,即使走 cmake 能找到,也没法自动 links 上,还得手动配各种 link
有进展了吗
Bot detected the issue body's language is not English, translate it automatically.
Has there any progress?