c++ - 将 GLFW 静态链接到 CMake 到可执行文件
问题描述
在我的项目中,我想将 GLFW 静态链接到我的主可执行文件,但是当我尝试这样做时,我的 CMakeLists 没有任何错误,而我的主可执行文件的错误只是说 GLFW/glfw3.h 文件不是一个有效的文件。
这是我的 CMakeLists.txt 代码:
cmake_minimum_required(VERSION 3.0.0)
project(openGL VERSION 1.0.0)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(L:\glfw-3.3.2)
add_executable(main main.cpp)
target_link_libraries(main glfw)
find_package(OpenGL REQUIRED)
target_link_libraries(main OpenGL::GL)
我的主要可执行文件:
#include <iostream>
#include <GLFW/glfw3.h>
using namespace std;
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
确切的错误代码:
cannot open source file "GLFW/glfw3.h/"
解决方案
推荐阅读
- java - 如何在运行时从 java 程序编译和运行 scala 代码?
- flash - 如何在 ActionScript 2 中绘制虚线?
- javascript - 为什么我的 javascript 函数中的 switch-case 不起作用?
- java - 需要在java中反转循环
- php - 点击域名模式应该像弹出窗口一样打开
- css - 如何在 Alfresco 中更改 aikau-1.0.101.10.jar 中的 CSS 文件
- laravel - 如何从复选框选中的laravel设置值变量?
- scala - 在 scala 中写入 JDBC 源
- jquery - 如何在输入时触发输入文本中的事件?
- ios - swift:在执行另一个动作后调用动作