I would like to know the reason why the makefile link order still results in an undefined reference error.

Asked 1 years ago, Updated 1 years ago, 517 views

Question details

The following error occurs when I compile, but I don't know why.
undefined reference to glfwInitWhat is the cause of the undefined reference?
Include files, links, and so on.

Status

FrameWork.a uses glew,glfw,opengl

What I checked

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

Where do I get it

glew:https://glew.sourceforge.net/
glfw:https://www.glfw.org/

Reference Site

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

Enter a description of the image here

$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();
    }

c++ linux windows mingw

2022-12-20 09:16

1 Answers

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.


2022-12-20 09:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.