Simple linking Problem (driving me nuts!)

Aug 29, 2018 at 12:22am
I'm using the latest (or close to it) version of gnu c++.
I have opengl dev libraries dated 30/7/2017 (not sure what version).

The linker is finding the libraries but giving me the following messages:

d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:42: undefined reference to `glCreateProgram@0'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:45: undefined reference to `glCreateShader@4'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:54: undefined reference to `glShaderSource@16'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:57: undefined reference to `glCompileShader@4'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:61: undefined reference to `glGetShaderiv@12'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:65: undefined reference to `glAttachShader@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:68: undefined reference to `glCreateShader@4'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:77: undefined reference to `glShaderSource@16'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:80: undefined reference to `glCompileShader@4'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:84: undefined reference to `glGetShaderiv@12'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:88: undefined reference to `glAttachShader@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:91: undefined reference to `glLinkProgram@4'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:95: undefined reference to `glGetProgramiv@12'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:99: undefined reference to `glGetAttribLocation@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:112: undefined reference to `glGenBuffers@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:113: undefined reference to `glBindBuffer@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:114: undefined reference to `glBufferData@16'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:117: undefined reference to `glGenBuffers@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:118: undefined reference to `glBindBuffer@8'
d:/my_projects/cubic_mahjong/working/source/main/c++/opengl.cpp:119: undefined reference to `glBufferData@16'

Thanks in advance for any help. Usually I would find a solution to
these kind of problems.. but I can't get to the bottom of this one.

Thanks.


Aug 29, 2018 at 12:33am
Why do you say "the linker is finding the libraries"? It doesn't seem like it.
What does your compile command look like?
Last edited on Aug 29, 2018 at 12:33am
Aug 29, 2018 at 2:27am
Here's the entire make file:

GamePath = d:/my_projects/cubic_mahjong/
ProjectPath = d:/my_projects/cubic_mahjong/working/
SourcePath = $(ProjectPath)source/main/c++/
HeaderPath = $(ProjectPath)source/main/headers/
UtilsSourcePath = $(ProjectPath)utilities/c++/
UtilsHeaderPath = $(ProjectPath)source/utilities/headers/
ResourcesPath = $(ProjectPath)resources/
ExternalHeaderPath = $(ProjectPath)headers/
Win32WrapperSourcePath = $(ProjectPath)source/win32_wrapper/c++/
Win32WrapperHeaderPath = $(ProjectPath)source/win32_wrapper/headers/
LibPath = d:/tools/mingw/lib/
ObjPath = $(ProjectPath)object/
Switches = -c -g

# -g = debug info
# -c = compile (no link)
# -mwindows = remove commandline window
# $(ResourcesPath)out_think_res.o
# $(LibPath)avcodec.lib

Objs = main.o opengl.o preferences_script.o system.o ui_script.o user_interface.o video.o window.o
Libs = $(LibPath)libstdc++.a $(LibPath)libSdl2.dll.a $(LibPath)libSDL2_image.dll.a $(LibPath)libopengl32.a $(LibPath)libglu32.a $(LibPath)libglaux.a

$(ProjectPath)cubic_Mahjong : $(Objs)
gcc -mwindows -o$(GamePath)cubic_mahjong $(Objs) $(Libs)

main.o : $(SourcePath)main.cpp $(UtilsHeaderPath)utils.h
gcc -I $(ExternalHeaderPath) $(Switches) $(SourcePath)main.cpp

ui_script.o : $(SourcePath)ui_script.cpp $(UtilsHeaderPath)utils.h
gcc $(Switches) $(SourcePath)ui_script.cpp

preferences_script.o : $(SourcePath)preferences_script.cpp $(UtilsHeaderPath)utils.h
gcc $(Switches) $(SourcePath)preferences_script.cpp

window.o : $(SourcePath)window.cpp $(HeaderPath)stdafx.h
gcc $(Switches) $(SourcePath)window.cpp

system.o : $(SourcePath)system.cpp $(UtilsHeaderPath)utils.h
gcc $(Switches) $(SourcePath)system.cpp

user_interface.o : $(SourcePath)user_interface.cpp $(UtilsHeaderPath)utils.h
gcc $(Switches) $(SourcePath)user_interface.cpp

video.o : $(SourcePath)video.cpp $(UtilsHeaderPath)utils.h
gcc -I $(ExternalHeaderPath) $(Switches) $(SourcePath)video.cpp

opengl.o : $(SourcePath)opengl.cpp $(UtilsHeaderPath)utils.h
gcc $(Switches) $(SourcePath)opengl.cpp

.PHONY : clean
clean :
del *.o

Aug 29, 2018 at 2:51am
You didn't answer my question about why you said the linker was finding the libraries. What makes you think that?

Where did you get that strange looking makefile?

You don't normally need to tell the compiler where stdc++ is.
Normally you would set a library path like: -Ld:/tools/mingw/lib
(assuming all the opengl and sdl libraries under mingw/lib).

Then you would mention the libraries on the linking line something like:
-lGL -lGLU -lglut -lglaux -lSDL2 -lSDL2_image -lm
(the last is for the math library, which may or may not be needed).

Although I don't use windows, so maybe you need to do it like:
-lopengl32 -lglu32

Try some variations of those. With/without the 32's and the "open".
Aug 29, 2018 at 3:40am
>You didn't answer my question about why you said the linker was finding the libraries. What >makes you think that?

Because the compiler says so during compilation if it can't find it on disk.






Aug 29, 2018 at 5:07am
I see. It seems strange to me that you have files that end .dll.a, but I don't know about windows, so I guess that's the case. Anyway, you obviously don't want to answer my questions so hopefully what I've already said can help a little.
Aug 29, 2018 at 9:29pm
Sorry I didn't answer straight away. .dll.a libraries are import libraries in windows.
You need to link them into your program and then place the .dll in your path
so your program can run.

I'm sure this problem isn't c linkage either (as the libraries don't use c++ name mangling)
as I specify this to the compiler also.

The *only* thing I can think of that's left is that the libraries aren't the right version.

Thanks for the help so far.




Aug 30, 2018 at 12:44am
OpenGL is a C library. If the linker is complaining about missing mangled symbols, that means the compiler added references to functions that it thought were from C++, so that means the signatures didn't have the required extern "C". The solution is to add it yourself.
1
2
3
extern "C"{
#include <foo.h>
}
Topic archived. No new replies allowed.