The following error occurs when I compile, but I don't know why.
undefined reference to glfwInit
What is the cause of the undefined reference?
Include files, links, and so on.
FrameWork.a uses glew,glfw,opengl
The libraries used are opengl, glfw, glew, freetype.
1. Order of reference site If A depends on B from the site, then A must come before B. I wrote it in order of dependence on
, but I got the following error.
2. Link and execute in various order
3. Check the file name and refer to the presented image
4,Glew32 and glew32s experiment
glew:https://glew.sourceforge.net/
glfw:https://www.glfw.org/
Order: https://stackoverflow.com/questions/48819869/linker-error-on-glfw-on-linux-x11
Place 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)
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/freeetype.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/freeetype
-include$(DEP)
US>clean:
rm-f./$(OBJ_DIR)/*.o*.out./$(OBJ_DIR)/*.d$(PRG)
#defineGLEW_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::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 (size))
camera->setPosition(glm::vec3(0,0,10));
camera->setLook(glm::vec3(0,0,-1));
while(*FrameWork::WindowContext)
{
camera->frameBuffer->OffScreenRender_Enable();
camera->frameBuffer->OffScreenRender_Disable();
camera->shader->setEnable();
camera->frameBuffer->ScreenRender_Enable();
camera->shader->setUniformSampler 2D("uImage", 0, camera->frameBuffer->texture);
camera->frameBuffer->ScreenRender();
camera->frameBuffer->ScreenRender_Disable();
camera->shader->setDisable();
FrameWork::Window::windowContext->SwapBuffers();
}
From the error message
/usr/bin/ld:/home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj): (.text$mn+0x30): undefined reference to `__imp_SetCursor'
This indicates that _imp_SetCursor
contained in User32.lib
is required to invoke SetCursor
in the Windows API.
Of course, SetCursor
included in User32.dll
is required at runtime.
There is no point in linking Windows binaries on Linux, so you may want to change your mind.
609 GDB gets version error when attempting to debug with the Presense SDK (IDE)
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
571 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
616 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.