92897


### 質問内容

コンパイルを行うと以下のエラーが起きますが原因がわかりません。  
`undefined reference to glfwInit`未定義の参照とあとりますが何が原因なのでしょうか？  
インクルードファイル、リンク、ともに行っています。

### 状況

FrameWork.aはglew,glfw,openglを使っています

### 調べたこと

利用ライブラリはopengl,glfw,glew,freetypeです。

１，参考サイトの順序サイトより`AがBに依存する場合AはBよりも前に来ないと行かない`を参考に依存する順番に記述しましたが以下のエラーがでます。

２，様々な順序でリンクして実行  
３，ファイル名を確認、提示画像参照  
４，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

[![画像の説明をここに入力](https://i.stack.imgur.com/bX9kp.png)](https://i.stack.imgur.com/bX9kp.png)

#### エラー(長いため一部省略)

[code]

    $ 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
    
[/code]

##### makefile

[code]

    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)
    
    
[/code]

#### ソースコード

[code]

    #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();
        }
    
    
[/code]


CC BY-SA 4.0
2022-12-18T04:17:58.827
92860
2022-12-19T11:15:57.220
2022-12-19T11:15:57.220
4236
55177
question
c++ linux windows mingw
makefile リンク順序を揃えても未定義の参照というエラーになる原因が知りたい


エラーメッセージより

>
[code]

>     /usr/bin/ld:
> /home/linux/Library/lib/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x30):
> undefined reference to `__imp_SetCursor'
>  
[/code]

これは、[Windows APIの`SetCursor`](https://learn.microsoft.com/en-
us/windows/win32/api/winuser/nf-winuser-
setcursor)を呼び出すために`User32.lib`に含まれている`__imp_SetCursor`が必要なことを指摘しています。  
もちろん実行時には`User32.dll`に含まれる`SetCursor`が必要です。

Linux上でWindowsバイナリをリンクしても何の意味もありませんので、考えを改めることをお勧めします。


CC BY-SA 4.0
2022-12-19T11:14:19.203
92897
2022-12-19T11:14:19.203
4236
92860
answer