OpenGL GLFW:对“glfwInit"的未定义引用 [英] OpenGL GLFW: undefined reference to 'glfwInit'

查看:79
本文介绍了OpenGL GLFW:对“glfwInit"的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到这个问题已经在 StackOverflow 和其他网站上多次问过了;在查看了这些资源后,我仍然不知所措.

I realize that this question has been asked many times on StackOverflow and on other sites; after reviewing these resources I am still at a loss.

我只是想让 OpenGL 在我的机器(Windows 7 64 位)上使用 GLFW.

I am simply trying to get OpenGL working on my machine (Windows 7 64-bit) with GLFW.

我遇到的问题与许多其他人遇到的问题相同:我收到了单一链接器错误:对‘glfwInit’的未定义引用."我试图编译的代码是最简单的(在文件 Test.cpp 中).

The issue I am having is the same as many others have: I am getting the singular linker error: "undefined reference to 'glfwInit'." The code I am trying to compile is the simplest possible (in a file Test.cpp).

#include <iostream>
#include <GLFW/glfw3.h>
int main()
{
    std::cout << "hello world" << std::endl;
    glfwInit();
    return 0;
}

我正在使用一个简单的 Makefile 来尝试编译:

I am using a simple Makefile to attempt to compile:

Test: Test.o
    g++ -o Test  -L./lib -lglew32 -lglfw3 -lopengl32 -lglu32 -lgdi32 Test.o

Test.o: Test.cpp
    g++ -I./include -c Test.cpp

附加信息:
* 使用g++编译(MinGW32)
* lib文件夹包含glfw3.dll、libglfw3.a和libglfw3dll.a(从GLFW网站下载的Win32版本-Windows预编译库)
* include 文件夹包含一个名为 GLFW 的文件夹,其中包含 glfw3.h 和 glfw3native.h(来自下载的 GLFW - include 文件夹)

Additional information:
* Using g++ to compile (MinGW32)
* The lib folder contains glfw3.dll, libglfw3.a, and libglfw3dll.a (Win32 version downloaded from GLFW website - Windows pre-compiled library)
* The include folder contains a folder named GLFW, which contains glfw3.h and glfw3native.h (from downloaded GLFW - include folder)

我试过了:
* 使用 GLFW 的 64 位版本
* 使用 IDE(Eclipse、VS)
* GLFW 未定义引用
中的建议* 中的建议是未定义的引用/未解析的外部符号错误,我该如何解决?(交换链接参数顺序)
* OpenGL 与 Eclipse CDT + MinGW + GLEW + GLFW 中的建议:未定义的引用
* 尝试使用 CMake 自己编译库,但没有看到在此过程中创建的任何 .a、.lib 或 .dll 文件.

I have tried:
* Using the 64-bit version from GLFW
* Using IDEs (Eclipse, VS)
* The suggestion in GLFW Undefined References
* Suggestions in What is an undefined reference/unresolved external symbol error and how do I fix it? (swapping linking argument order)
* Suggestion in OpenGL with Eclipse CDT + MinGW + GLEW + GLFW: Undefined References
* Attempted to use CMake to compile the libraries myself, but do not see any .a, .lib, or .dll files created in the process.

如果其他信息有帮助,请告诉我.

Please let me know if additional information would be helpful.

推荐答案

终于在 MANY 几个小时后解决了我的问题.

Finally figured out my issue MANY hours later.

将 libglfw3.a 文件留在与 glfw3.dll 相同的目录中(如果尝试动态链接)会混淆链接器.如果动态链接,请删除它 - 您只需要 dll 和/include 文件夹.

Leaving the libglfw3.a file in the same directory as the glfw3.dll (if attempting dynamic linking) will confuse the linker. Delete it if linking dynamically - all you need is the dll and the /include folder.

另外,添加

#define GLFW_DLL

如果与 DLL 链接,则在包含语句的上方.

above the include statement if linking with a DLL.

这篇关于OpenGL GLFW:对“glfwInit"的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆