使用vcpkg配置Visual Studio开发环境下的opengl类项目
这个方法适合跨设备开发,因为只需对项目配置文件进行更改,就可以只在编译时才下载相应依赖,在项目上传时(Git或其他VCS)可以只上传源代码和配置文件,毋需上传外部依赖的库。以下是详细步骤: 1. 在开始菜单的Visual Studio的文件夹下打开Developer Command Prompt,输入vcpkg integrate install,将本机上所有通过vcpkg安装的库都实现所有项目共用。 2. 在你的项目中,打开工具-->命令列-->开发者用Powershell,在Powershell窗口中输入:$env:VCPKG_ROOT = "C:\path\to\vcpkg" (路径改为vcpkg安装的路径,VS一般已经集成,位置在VS路径\VC\vcpkg。) $env:PATH = "$env:VCPKG_ROOT;$env:PATH" 3. 在Powershell窗口中输入:vcpkg new --application,项目就会建立一份vcpkg的配置文件以获取远端的依赖包 4. 在Powershell窗口中依次输入: vcpkg add port glfw3 vcpkg add port glew vcpkg add port freeglut vcpkg add port glm vcpkg add port glad 最基本的库时glfw3,其他根据需求添加。 5. 在你的项目中,打开项目-->“项目名称”属性-->在左侧面板中选择vcpkg,然后在是否使用vcpkg manifest中选择“是” 6. 配置完成,在源代码中正常include就好,库的路径和其他平台一致。 注1:intellisense可能不会立即识别出依赖库是否准备完成,关闭项目并重新打开即可解决问题。 注2:使用glm库的方法时,如果出现类似 error "GLM: GLM_GTX_dual_quaternion is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it....