无法链接GLEW库

问题描述 投票:0回答:1

这是我的makefile:

### OUTPUT ###
BUILD = Build

### SOURCES ###
SRC = Src/main\
      Src/Game/Game\
      Src/Shader/Shader

### OBJECTS ###
OBJ = $(addsuffix .o, $(addprefix $(BUILD)/, $(SRC)))

### INCLUDES ###
INC = -ID:/Development/OpenGL/Glfw/include/GLFW\
      -ID:/Development/OpenGL/Glew/glew-2.1.0/include/GL\
      -ID:/Development/OpenGL/Glm/glm-0.9.9.8/glm\
      -ISrc/Game\
      -ISrc/Shader/

### LIBRARIES ###
LIB = -LD:/Development/OpenGL/Glew/glew-2.1.0/lib/Release/Win32 -lglew32s\
      -LD:/Development/OpenGL/Glfw/lib-mingw -lglfw3\
      -lopengl32

### LINKER FLAGS ###
LFLAGS = $(LIB)

### COMPILER FLAGS
CFLAGS = $(INC)

### COMPILER ###
CC = g++

all: $(BUILD)/test.exe

$(BUILD)/test.exe: $(OBJ)
    @echo LINKING $^
    @$(CC) $(LFLAGS) -o $@ $^

$(BUILD)/%.o: %.cpp
    @echo COMPILING $<
    @mkdir -p $(subst /,\,$(dir $@))
    @$(CC) $(CFLAGS) -M -MT $@ -o $(patsubst %.o, %.d, $@) $<
    @$(CC) $(CFLAGS) -o $@ -c $<

-include $(OBJ:.o=.d) 

.PHONY: clean

clean:
    @echo CLEANING......
    @@rm -rf $(BUILD)/*

我在这里指定所需的库:

### LIBRARIES ###
LIB = -LD:/Development/OpenGL/Glew/glew-2.1.0/lib/Release/Win32 -lglew32s\
      -LD:/Development/OpenGL/Glfw/lib-mingw -lglfw3\
      -lopengl32

并在此处链接它们:

$(BUILD)/test.exe: $(OBJ)
    @echo LINKING $^
    @$(CC) $(LFLAGS) -o $@ $^

我遇到的错误是:

LINKING Build/Src/main.o Build/Src/Game/Game.o Build/Src/Shader/Shader.o
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0xb): undefined reference to `__glewUseProgram'
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0x33): undefined reference to `__glewCreateShader'
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0x48): undefined reference to `__glewShaderSource'
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0x70): undefined reference to `__glewCompileShader'
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0xdf): undefined reference to `__glewCreateShader'
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0xf4): undefined reference to `__glewShaderSource'
Build/Src/Shader/Shader.o:Shader.cpp:(.text+0x11c): undefined reference to `__glewCompileShader'

我也定义了GLEW_STATIC

#define GLEW_STATIC
#include "glew.h"

我正在使用mingw32,并且正在使用mingw32-make all调用makefile我不知道为什么它找不到那些符号...我一直在努力弄清楚2个小时。

编辑:这是实际的链接命令:

g++ -LD:/Development/OpenGL/Glew/glew-2.1.0/lib/Release/Win32 -lglew32s -LD:/Development/OpenGL/Glfw/lib-mingw -lglfw3 -lopengl32 -o Build/test.exe Build/Src/main.o Build/Src/Game/Game.o Build/Src/Shader/Shader.o

这是我的makefile:###输出###构建=构建###源### SRC = Src / main \ Src / Game / Game \ Src / Shader / Shader ###对象### OBJ = $(addsuffix .o,$(addprefix $(BUILD)/,$(SRC)))...

c++ c opengl makefile
1个回答
2
投票

在单通链接器中(与当今几乎所有链接器一样),项的顺序至关重要。特别是,必须确保所有对象文件都在链接库first

© www.soinside.com 2019 - 2024. All rights reserved.