學習OpenGL時compile遇到這個問題,頭疼了半天時間,誰幫我解答一下
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
// settings
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
while (!glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
1>------ 已啟動生成: 專案: ConsoleApplication3, 配置: Debug Win32 ------
1>First.cpp
1>First.obj : error LNK2019: 無法決議的外部符號 _gladLoadGLLoader,該符號在函式 _main 中被參考
1>First.obj : error LNK2001: 無法決議的外部符號 _glad_glViewport
1>E:\OpenGL\OpenGL_Study\First\Debug\ConsoleApplication3.exe : fatal error LNK1120: 2 個無法決議的外部命令
1>已完成生成專案“ConsoleApplication3.vcxproj”的操作 - 失敗。
========== 生成: 成功 0 個,失敗 1 個,最新 0 個,跳過 0 個 ==========
uj5u.com熱心網友回復:
首先得確定自己建立的是不是一個空專案(empty project),不然glad.c會與其他頭檔案沖突。包含目錄和銜接庫都注意重新得設定一下。
建立專案后新建一個cpp檔案貼上原代碼,然后在頭檔案夾處右鍵添加glad.c檔案就之后可以正常運行了~
uj5u.com熱心網友回復:
你需要把glad.c檔案添加到專案當中。uj5u.com熱心網友回復:
2樓正解
uj5u.com熱心網友回復:
把glad.c檔案添加到專案當中 具體是指??什么uj5u.com熱心網友回復:
下載glad.lib檔案,添加依賴庫,就OK了uj5u.com熱心網友回復:
目測是沒把glad.c檔案添加到專案中,或者添加到專案中了vs沒檢測到。建議:在專案中添加一個源檔案glad.c (或glad.cpp),把glad.c檔案內容原封不動拷過去,save
uj5u.com熱心網友回復:
樓上老哥正解, 我也遇到一樣的問題, 以為把glad.c放在同一檔案夾就可以了. 實際上需要添加到工程里面去. 右擊源檔案-->添加現有項-->找到glad.c添加進去就可以了.uj5u.com熱心網友回復:
#7老哥點贊uj5u.com熱心網友回復:
參看我的博客:https://blog.csdn.net/gongzhu110/article/details/80032602
uj5u.com熱心網友回復:
如果添加glad.c 然后就是glad.c檔案 編譯出錯 name class找不到 xcode 這是什么問題uj5u.com熱心網友回復:
將glad.c檔案添加到當前專案中,可以解決問題,親試有效轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/32479.html
上一篇:求大佬改一下
