So I've started learning makefiles today for a project I've been working on. The project uses OpenGL and GDI. I decided to dive right into make files and so far, everything compiles but at the very end, it gives a bunch of undefined references. Thing is, when compiled in codeblocks, the project compiles just fine! I decided to learn make files just for the sake of learning it but now I cannot figure out what I did wrong at all :S I'd like someone to take a look at it and maybe help me on what I'm doing wrong please.

The errors I get is as follows (below it has my makefile):

obj/Calculations.o:Calculations.cpp:(.text+0x3d7): undefined reference to `glGet
obj/Calculations.o:Calculations.cpp:(.text+0x3f0): undefined reference to `glGet
obj/Calculations.o:Calculations.cpp:(.text+0x409): undefined reference to `glGet
obj/Calculations.o:Calculations.cpp:(.text+0x465): undefined reference to `gluPr
obj/Calculations.o:Calculations.cpp:(.text+0x50c): undefined reference to `gluPr
obj/Calculations.o:Calculations.cpp:(.text+0x572): undefined reference to `glGet
obj/Calculations.o:Calculations.cpp:(.text+0x58b): undefined reference to `glGet
obj/Calculations.o:Calculations.cpp:(.text+0x5a4): undefined reference to `glGet
obj/Calculations.o:Calculations.cpp:(.text+0x6a3): undefined reference to `gluUn
obj/Calculations.o:Calculations.cpp:(.text+0x7db): undefined reference to `gluUn
obj/Commands.o:Commands.cpp:(.text+0x115): undefined reference to `wglGetCurrent
obj/Commands.o:Commands.cpp:(.text+0x12b): undefined reference to `GetDeviceCaps
obj/Commands.o:Commands.cpp:(.text+0x1bb): undefined reference to `CreateFontA@5
obj/Commands.o:Commands.cpp:(.text+0x1d3): undefined reference to `SelectObject@
obj/Commands.o:Commands.cpp:(.text+0x22b): undefined reference to `SelectObject@
obj/Commands.o:Commands.cpp:(.text+0x239): undefined reference to `DeleteObject@
obj/Commands.o:Commands.cpp:(.text+0x260): undefined reference to `glDeleteLists
obj/Commands.o:Commands.cpp:(.text+0x2d4): undefined reference to `glGetIntegerv
obj/Commands.o:Commands.cpp:(.text+0x38f): undefined reference to `glGetIntegerv
obj/Commands.o:Commands.cpp:(.text+0x3c4): undefined reference to `glGetIntegerv
obj/Commands.o:Commands.cpp:(.text+0x4b0): undefined reference to `glColor4f@16'

obj/Images.o:Images.cpp:(.text+0xa90): undefined reference to `DeleteDC@4'
obj/Images.o:Images.cpp:(.text+0xaa1): undefined reference to `DeleteObject@4'
obj/Images.o:Images.cpp:(.text+0x1202): undefined reference to `CreateCompatible
obj/Images.o:Images.cpp:(.text+0x1240): undefined reference to `SelectObject@8'
obj/Images.o:Images.cpp:(.text+0x125d): undefined reference to `GetObjectA@12'
obj/Images.o:Images.cpp:(.text+0x1381): undefined reference to `GetDIBits@28'
obj/MemoryCommunication.o:MemoryCommunication.cpp:(.text+0x8f): undefined refere
nce to `glGetIntegerv@8'
obj/MemoryCommunication.o:MemoryCommunication.cpp:(.text+0x11b): undefined refer
ence to `glGetIntegerv@8'
obj/MemoryCommunication.o:MemoryCommunication.cpp:(.text+0x134): undefined refer
ence to `glGetDoublev@8'
obj/MemoryCommunication.o:MemoryCommunication.cpp:(.text+0x14d): undefined refer
ence to `glGetDoublev@8'
obj/RSHooks.o:RSHooks.cpp:(.text+0x984): undefined reference to `glGetIntegerv@8
obj/RSHooks.o:RSHooks.cpp:(.text+0x99d): undefined reference to `glGetDoublev@8'

obj/RSHooks.o:RSHooks.cpp:(.text+0x9b6): undefined reference to `glGetDoublev@8'

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMai
collect2: ld returned 1 exit status
make: *** [bin/Windows/OpenGL32.dll] Error 1

My makefile is as follows:

WinGPP = g++
LinGPP = g++
BinDIR = bin
ObjDIR = obj
SrcDIR = src
WinOUT = OpenGL32.dll
LinOUT =
WinDIR = $(BinDIR)/Windows
LinDIR = $(BinDIR)/Linux

WinDEP = -static-libgcc -static-libstdc++ -luser32 -lgdi32 -lglu32 -lopengl32 -s -o
LinDEP = -User32 -Gdi32 -Glu32 -OpenGL32

WinARGS = -std=c++0x -Wall -O0 -DOPENGL32_EXPORTS -s -c
LinARGS = -DLINUX -O3 -s -c 

HppFiles = \
    $(SrcDIR)/Calculations.hpp \
    $(SrcDIR)/Commands.hpp \
    $(SrcDIR)/Defines.hpp \
    $(SrcDIR)/Functions.hpp \
    $(SrcDIR)/GLHook.hpp \
    $(SrcDIR)/Images.hpp \
    $(SrcDIR)/MemoryCommunication.hpp \
    $(SrcDIR)/Models.hpp \
    $(SrcDIR)/RSHooks.hpp \
    $(SrcDIR)/Serialize.hpp \
    $(SrcDIR)/SharedMemory.hpp \
    $(SrcDIR)/Vector3D.hpp \

CppFiles = \
    $(SrcDIR)/Calculations.cpp \
    $(SrcDIR)/Commands.cpp \
    $(SrcDIR)/Functions.cpp \
    $(SrcDIR)/GLHook.cpp \
    $(SrcDIR)/Images.cpp \
    $(SrcDIR)/MemoryCommunication.cpp \
    $(SrcDIR)/Models.cpp \
    $(SrcDIR)/RSHooks.cpp \
    $(SrcDIR)/Serialize.cpp \
    $(SrcDIR)/SharedMemory.cpp \
    $(SrcDIR)/Vector3D.cpp \

ObjFiles = \
    $(ObjDIR)/Calculations.o \
    $(ObjDIR)/Commands.o \
    $(ObjDIR)/Functions.o \
    $(ObjDIR)/GLHook.o \
    $(ObjDIR)/Images.o \
    $(ObjDIR)/MemoryCommunication.o \
    $(ObjDIR)/Models.o \
    $(ObjDIR)/RSHooks.o \
    $(ObjDIR)/Serialize.o \
    $(ObjDIR)/SharedMemory.o \
    $(ObjDIR)/Vector3D.o \

    @echo "  Instructions For Making OpenGL32:"
    @echo "    For Windows:     make windows"
    @echo "    For Linux:       make linux"
    @echo "    For Both:        make both"
    @echo "    To Clean Files:  make clean"

everything: linux windows

linux: $(ObjFiles) cc -o linux $(ObjFiles)

windows: $(WinDIR)/$(WinOUT)
    @echo "Finished Building OpenGL32."

$(WinDIR)/$(WinOUT): $(ObjFiles)
    @echo "Linking Object Files.."
    @mkdir -p $(BinDIR)
    @$(WinGPP) -Wl,$(SrcDIR)/OpenGL32.def $(WinDEP) $(WinDIR)/$(WinOUT) $(ObjFiles)

$(ObjDIR)/Calculations.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Calculations.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Calculations.o $(SrcDIR)/Calculations.cpp -lOpenGL32

$(ObjDIR)/Commands.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Commands.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Commands.o $(SrcDIR)/Commands.cpp

$(ObjDIR)/Defines.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Defines.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Defines.o $(SrcDIR)/Defines.cpp

$(ObjDIR)/Functions.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Functions.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Functions.o $(SrcDIR)/Functions.cpp

$(ObjDIR)/GLHook.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: GLHook.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/GLHook.o $(SrcDIR)/GLHook.cpp

$(ObjDIR)/Images.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Images.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Images.o $(SrcDIR)/Images.cpp

$(ObjDIR)/MapStructures.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: MapStructures.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/MapStructures.o $(SrcDIR)/MapStructures.cpp

$(ObjDIR)/MemoryCommunication.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: MemoryCommunication.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/MemoryCommunication.o $(SrcDIR)/MemoryCommunication.cpp

$(ObjDIR)/Models.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Models.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Models.o $(SrcDIR)/Models.cpp

$(ObjDIR)/RSHooks.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: RSHooks.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/RSHooks.o $(SrcDIR)/RSHooks.cpp

$(ObjDIR)/Serialize.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Serialize.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Serialize.o $(SrcDIR)/Serialize.cpp

$(ObjDIR)/SharedMemory.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: SharedMemory.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/SharedMemory.o $(SrcDIR)/SharedMemory.cpp

$(ObjDIR)/Vector3D.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: Vector3D.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/Vector3D.o $(SrcDIR)/Vector3D.cpp

$(ObjDIR)/main.o: $(CppFiles) $(HppFiles)
    @echo "    Compiling: main.cpp"
    @mkdir -p $(ObjDIR)
    @$(WinGPP) $(WinARGS) -o $(ObjDIR)/main.o $(SrcDIR)/main.cpp

Recommended Answers

All 3 Replies

I tried that.. It didn't work. The solution was to change:

WinDEP = -static -static-libgcc -static-libstdc++ -shared -s -o


$(WinDIR)/$(WinOUT): $(ObjFiles)
    @echo "Linking Object Files.."
    @mkdir -p $(WinDIR)
    @$(WinGPP) -Wl,$(SrcDIR)/OpenGL32.def $(WinDEP) $(WinDIR)/$(WinOUT) $(ObjFiles) -lgdi32 -lglu32 -lopengl32

But now it warns me of:

Warning: resolving _GLHook_wglSwapLayerBuffers by linking to _GLHook_wglSwapLaye

Warning: resolving _GLHook_wglSwapMultipleBuffers by linking to _GLHook_wglSwapM

Warning: resolving _GLHook_wglUseFontBitmapsA by linking to _GLHook_wglUseFontBi

Which isn't a problem but it is really really annoying. Anyway to hide that?

resolving _GLHook_wglSwapLayerBuffers by linking to _GLHook_wglSwapLayerBuffers@8

Hmm... Seems to have found a library built with the Microsoft toolchain instead of one built with the GCC toolchain. Shouldn't be a problem unless there is a major version mismatch. Personally, I wouldn't be happy about this, and would still put in the -L<search_for_library_here> linker options.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.