S
S
sddvxd2018-12-27 04:12:34
C++ / C#
sddvxd, 2018-12-27 04:12:34

Why is there an undefined reference here?

Hello!
I'm trying to compile the source file, the linker stumbles on this line:

#define GLEW_STATIC
#include <GL/glew.h>
#include <GL/glext.h>
#include <GLFW/glfw3.h>
...
glGenBuffers(0, 0);

C:/Qt/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w
64-mingw32/lib/../lib/glew32s.lib(tmp/glew_static/Release/Win32/glew.obj):(.text
$mn+0x7): undefined reference to `[email protected]'

I compile with the following command: g++ main.cpp -lglfw3 -lgdi32 -lopengl32 -lglew32s finds
all libraries, and this function (wglGetProcAddress) is defined in libopengl32.a, but the linker cannot find it. Please tell me why

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-12-28
@sddvxd

Please tell me why

Because the order in which the libraries are listed is important: in the list of libraries , the a b csymbols that the library needs bwill only be looked for in the library c, not in the a. If there are no cyclic dependencies between libraries (i.e., there is no one that adefines the symbol needed b, but bdefines the symbol needed a), then they can be ordered so that the linking will be successful (see topological sorting ). If there are cyclic dependencies, or it’s too lazy to sort, you can list the necessary libraries several times or take them into a group:
g++ main.cpp -Wl,--start-group -lglfw3 -lgdi32 -lopengl32 -lglew32s -Wl,--end-group

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question