質問内容
コンパイルを行うと以下のエラーが起きますが原因がわかりません。
undefined reference to glfwInit
未定義の参照とあとりますが何が原因なのでしょうか?
インクルードファイル、リンク、ともに行っています。
状況
FrameWork.aはglew,glfw,openglを使っています
調べたこと
利用ライブラリはopengl,glfw,glew,freetypeです。
1,参考サイトの順序サイトよりAがBに依存する場合AはBよりも前に来ないと行かない
を参考に依存する順番に記述しましたが以下のエラーがでます。
2,様々な順序でリンクして実行
3,ファイル名を確認、提示画像参照
4,glew32,glew32s共に実験
入手先
glew: https://glew.sourceforge.net/
glfw: https://www.glfw.org/
参考サイト
順序:https://stackoverflow.com/questions/48819869/linker-error-on-glfw-on-linux-x11
defineを配置:https://stackoverflow.com/questions/18475234/undefined-references-to-imp-glew-functions-with-mingw-gcc
環境
OS: ubuntu
エラー(長いため一部省略)
$ make
g++ obj/Main.o -o program -L../bin -lFrameWork ~/Library/lib/glew32s.lib ~/Library/lib/glfw3.lib ~/Library/lib/freetype.lib -lGL -ldl -lm -lGLU -lX11
/usr/bin/ld: /home/linux/Library/lib/glew32s.lib(tmp/glew_static/Release/x64/glew.obj):(.text$mn+0xd): undefined reference to `__imp_wglGetProcAddress'
/usr/bin/ld: /home/linux/Library/lib/glew32s.lib(tmp/glew_static/Release/x64/glew.obj):(.text$mn+0xf): undefined reference to `__imp_wglGetProcAddress'
//x64/glew.obj):(.text$mn+0x363): undefined reference to `__imp_glGetString'
/usr/bin/ld: /home/linux/Library/lib/glew32s.lib(tmp/glew_static/Release/x64/glew.obj):(.text$mn+0x2d): undefined reference to `__imp_wglGetCurrentDC'
/usr/bin/ld: /home/linux/Library/lib/glew32s.lib(tmp/glew_static/Release/x64/glew.obj):(.text$mn+0x1c): undefined reference to `__imp_wglGetProcAddress'
/usr/bin/ld: /home/linux/Library/lib/glew32s.lib(tmp/glew_static/Release/x64/glew.obj):(.text$mn+0x30): undefined reference to `__imp_wglGetProcAddress'
/usr/bin/ld: /home/linux/Library/lib/glew32s.lib(tmp/glew_static/Release/x64/glew.obj):(.text$mn+0x5c): undefined reference to `__imp_wglGetCurrentDC'
j):(.text$mn+0x105): undefined reference to `__imp_CloseClipboard'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x30): undefined reference to `__imp_SetCursor'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x3d): undefined reference to `__imp_LoadCursorW'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x4c): undefined reference to `__imp_SetCursor'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x5a): undefined reference to `__imp_SetCursor'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x13): undefined reference to `__imp_GetActiveWindow'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x2e): undefined reference to `__imp_ClientToScreen'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x3c): undefined reference to `__imp_SetCursorPos'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x37): undefined reference to `__imp_RegisterRawInputDevices'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x71): undefined reference to `__imp_RegisterRawInputDevices'
/usr/bin/ld: /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/wi
makefile
PRG :=program
OBJ_DIR :=obj
SRC_DIR :=src
DEP_DIR :=obj
DEP :=$(wildcard $(DEP_DIR)/*.d)
SRC :=$(wildcard $(SRC_DIR)/*.cpp)
OBJ :=$(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(notdir $(SRC))))
$(PRG): $(OBJ)
# $(CXX) $^ -o $@ -L../bin ~/Library/lib/glew32s.lib ~/Library/lib/glfw3.lib -lFrameWork ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
# $(CXX) $^ -o $@ -L../bin -lFrameWork ~/Library/lib/glfw3.lib ~/Library/lib/glew32s.lib ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
# $(CXX) $^ -o $@ -L../bin ~/Library/lib/glfw3.lib ~/Library/lib/glew32s.lib -lFrameWork ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
# $(CXX) $^ -o $@ -L../bin ~/Library/lib/glfw3.lib ~/Library/lib/glew32.lib -lFrameWork ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
# $(CXX) $^ -o $@ -L../bin ~/Library/lib/glew32.lib ~/Library/lib/glfw3.lib -lFrameWork ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
# $(CXX) $^ -o $@ -L../bin -lFrameWork ~/Library/lib/glew32.lib ~/Library/lib/glfw3.lib ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
# $(CXX) $^ -o $@ -L../bin -lFrameWork ~/Library/lib/glfw3.lib ~/Library/lib/glew32s.lib ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
$(CXX) $^ -o $@ -L../bin -lFrameWork ~/Library/lib/glew32s.lib ~/Library/lib/glfw3.lib ~/Library/lib/freetype.lib -ldl -lm -lGL -lGLU -lX11
$(OBJ_DIR)/%.o: src/%.cpp
$(CXX) -c -MMD -MP $< -o $@ -I ~/prg/2DFrameWork/src -I ~/Library -I ~/Library/freetype
-include $(DEP)
clean:
rm -f ./$(OBJ_DIR)/*.o *.out ./$(OBJ_DIR)/*.d $(PRG)
ソースコード
#define GLEW_STATIC
#include <iostream>
#include <memory>
#include <FrameWork.hpp>
#include "glfw/glfw3.h"
int main()
{
if (glfwInit() != GLFW_TRUE)
{
assert(0 && "glfw");
}
FrameWork::Window::windowContext = std::make_shared<FrameWork::Window>(glm::ivec2(800, 800), "Hello World");
FrameWork::Window::windowContext->setCurrentContext();
// OpenGL Verison 4.5 Core Profile
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if (glewInit() != GLEW_OK)
{
assert(0 && "glew");
}
glEnable(GL_DEPTH_TEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
glEnable(GL_MULTISAMPLE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//glCullFace(GL_FRONT);
FrameWork::Sprite::Init();
std::shared_ptr<FrameWork::Camera> camera = std::make_shared<FrameWork::Camera>(FrameWork::Window::windowContext);
camera->shader = std::make_shared<FrameWork::Shader>();
//camera->shader->Load("asset/shader/FrameBuffer_depth.vert", "asset/shader/FrameBuffer_depth.frag");
camera->shader->Load("asset/shader/FrameBuffer.vert", "asset/shader/FrameBuffer.frag");
camera->shader->setVertexAttribute(camera->frameBuffer->quadVAO, camera->frameBuffer->quadVBO, "vertexPosition", 4, sizeof(FrameWork::VertexAttribute_Sprite), 0);
camera->shader->setVertexAttribute(camera->frameBuffer->quadVAO, camera->frameBuffer->quadVBO, "vertexUV", 4, sizeof(FrameWork::VertexAttribute_Sprite), 3 * sizeof(float));
camera->setPosition(glm::vec3(0, 0, 10));
camera->setLook(glm::vec3(0, 0, -1));
while (*FrameWork::Window::windowContext)
{
camera->frameBuffer->OffScreenRender_Enable();
camera->frameBuffer->OffScreenRender_Disable();
camera->shader->setEnable();
camera->frameBuffer->ScreenRender_Enable();
camera->shader->setUniformSampler2D("uImage", 0, camera->frameBuffer->texture);
camera->frameBuffer->ScreenRender();
camera->frameBuffer->ScreenRender_Disable();
camera->shader->setDisable();
FrameWork::Window::windowContext->SwapBuffers();
}
glfwInit()
が含まれているライブラリを指定していないように見えますが、-lglfw3
等は指定していますか?pkg-config
が使える環境ならそれを使うのが良さそう。$(CXX) $^ -o $@ -L~/Library/lib/glfw3 -L~/Library/lib/glew32s -L~/Library/lib/freetype -ldl -lX11 -L./bin/FrameWork.a -lGL -lGLU -ldl -lGLESv2 -pthread
.lib
でまさか……とは思ったけど、そっからか……先は長そうですね。