问题描述
我为Win64修改了我的makefile,但是在编译时出现“未定义引用”错误,这很奇怪,因为Win32 makefile上不会发生这种情况。 OpenGL库全部包含在内,我修改了库目录以指向Win64 DLL。
尽管有数以百万计的警告,GLEW仍然可以正常工作。
makefile:
# Test Game Windows 64-bit Makefile
# copyright (C) 2020 MarioMario456
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation,either version 3 of the License,or
# any later version.
binaries/win64/testgame : source/main.cpp
i686-w64-mingw32-g++ source/main.cpp source/glew.c -Isource -Llibrary/win64 -lopengl32 -lglu32 -lglfw3 -lgdi32 -o binaries/win64/testgame
主要源文件:
/* Test Game Main Source File
* copyright (C) 2020 MarioMario456
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation,or
* any later version. */
#include <iostream>
#include <GLFW/glfw3.h>
#include "main.hpp"
using namespace std;
int main() {
// Game initialization
if (!glfwInit()) {
cout << "An error occurred while initializing the game. Please try again.";
return -1;
}
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
GLFWwindow* window = glfwCreateWindow(640,480,"3D Shooter",NULL,NULL);
glfwMakeContextCurrent(window);
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
int monitorWidth = mode->width;
int monitorHeight = mode->height;
int windowWidth,windowHeight;
glfwGetwindowSize(window,&windowWidth,&windowHeight);
glfwSetwindowPos(window,(monitorWidth-windowWidth)/2,(monitorHeight-windowHeight)/2);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
}
错误:
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x17): undefined reference to `glfwInit'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x52): undefined reference to `glfwWindowHint'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x7e): undefined reference to `glfwCreateWindow'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x8c): undefined reference to `glfwMakeContextCurrent'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x91): undefined reference to `glfwGetPrimaryMonitor'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x9f): undefined reference to `glfwGetVideoMode'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0xcc): undefined reference to `glfwGetwindowSize'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x107): undefined reference to `glfwSetwindowPos'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x112): undefined reference to `glfwWindowShouldClose'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x137): undefined reference to `glfwSwapBuffers'
C:\Users\(REDACTED)\AppData\Local\Temp\cc7Qjwm6.o:main.cpp:(.text+0x13c): undefined reference to `glfwPollEvents'
解决方法
我设法解决此问题,方法是切换到64位Windows,安装了64位版本的MinGW-w64,然后修改了makefile以使用“ x86_64-w64-mingw32-g ++”而不是“ i686-w64-mingw32” -g ++”。