做到作业三的时候发现调试有点麻烦,加上借用电脑跑虚拟机不太方便,摸索了从vcpkg开始到CMake项目运行的全流程。
01.配置vcpkg
参考的这篇文章:
https://blog.csdn.net/lhw330472787/article/details/140346948
vs2022自带的vcpkg不能使用,通过克隆仓库地址后,在目录内运行bat即可配置好。
git clone https://github.com/microsoft/vcpkg
./bootstrap-vcpkg.bat
02.安装OpenCV,Eigen
参考的这篇文章:
https://blog.csdn.net/lhw330472787/article/details/140346948
自己安装的时候正常安装,opencv用时比较久,如果CPU使用率低,可以回车一下看是安装完成还是出错了。
.\vcpkg.exe install eigen3:x64-windows
.\vcpkg.exe install opencv:x64-windows
.\vcpkg.exe integrate install
另外在安装包完成以后会提供CMakeLists的配置,例如这样的:
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/soft/vcpkg-master/scripts/buildsystems/vcpkg.cmake"
All MSBuild C++ projects can now #include any installed libraries. Linking will be handled automatically. Installing new libraries will make them instantly available.
如果忘记了可以再次运行
03.启动项目
使用VS2022打开文件夹会自动识别CMake项目:
启动:
错误处理:
实测过程中主要出现了多个报错:
ninja 无法构建:
https://www.cnblogs.com/mengde-booker/p/17963657
安装英文语言包。
PowerShell错误:
(win10)解决neo4j提示:Powershell,不是内部或外部命令_powershell不是内部或外部命令-CSDN博客
加入环境变量。
Eigen OpenCV错误:
实际上我的引用改为了:
#include <Eigen/Eigen>
#include <opencv2/opencv.hpp>
Win10环境下用CMake编译项目遇到与Eigen库相关的问题_cmake编译时找不到eigen-CSDN博客
总结:
我最终的配置文件是(Eigen3 OpenCV都需要配置):
cmake_minimum_required(VERSION 3.10)
project(Rasterizer)
#set(CMAKE_TOOLCHAIN_FILE "C:/soft/vcpkg-master/scripts/buildsystems/vcpkg.cmake")
#find_package(OpenCV REQUIRED)
set(-DCMAKE_TOOLCHAIN_FILE=C:/soft/vcpkg-master/scripts/buildsystems/vcpkg.cmake)
set(CMAKE_CXX_STANDARD 17)
#include_directories(/usr/local/include ./include)
find_package(Eigen3 CONFIG REQUIRED)
find_package(OpenCV CONFIG REQUIRED)
#find_package(OpenCV CONFIG REQUIRED)
# note: 10 additional targets are not displayed.
add_executable(Rasterizer main.cpp rasterizer.hpp rasterizer.cpp global.hpp Triangle.hpp Triangle.cpp Texture.hpp Texture.cpp Shader.hpp OBJ_Loader.h)
target_link_libraries(Rasterizer PRIVATE ${OpenCV_LIBRARIES})
target_link_libraries(Rasterizer PRIVATE Eigen3::Eigen )
注:如果是黑屏检查一下是否有obj模型文件,
指定运行参数的方法还没找到,目前是指定shader的运行方式