PDA

View Full Version : linking problem in minGW



scratty
10-07-2005, 09:59 AM
Hi!
I decided to split a program into pieces since it has become large enough. So I split it up into a few c-files and made the appropriate h-files. Then I created a makefile. Since it's my first time doing this, I stumbled across several difficulties before getting it to work satisfactory. So, I got it to work under linux in school. However, as I attempt to run a modified version of the makefile under minGW at home, it returns a number of errors. I did a test program which consists of one c-file and its h-file (main.c and main.h) just to simplify the debugging somewhat. Here's the errors I get under minGW:

$ make
gcc -g -Wall -Ic:/Program/mingw/include/ -pipe -fpic -DSHM -Lc:/Program/mingw/lib -lglut32 -lGLU32 -lOpenGL32 -lgdi32 -luser32 -lm main.o -o labb3_4
main.o(.text+0x7cc): In function `solidEllipsoid':
c:/mina dokument/program/c/cg/test/main.c:116: undefined reference to `glBegin@4'
main.o(.text+0x806):c:/mina dokument/program/c/cg/test/main.c:121: undefined reference to `glNormal3f@12'
main.o(.text+0x81d):c:/mina dokument/program/c/cg/test/main.c:123: undefined reference to `glTexCoord2f@8'
main.o(.text+0x830):c:/mina dokument/program/c/cg/test/main.c:125: undefined reference to `glTexCoord2f@8'
main.o(.text+0x924):c:/mina dokument/program/c/cg/test/main.c:126: undefined reference to `glVertex3f@12'
main.o(.text+0x938):c:/mina dokument/program/c/cg/test/main.c:130: undefined reference to `glNormal3f@12'
main.o(.text+0x94f):c:/mina dokument/program/c/cg/test/main.c:132: undefined reference to `glTexCoord2f@8'
main.o(.text+0x962):c:/mina dokument/program/c/cg/test/main.c:134: undefined reference to `glTexCoord2f@8'

etc...it seems like the compiler doesn't recognize any of the opengl functions.
If I compile the same file without make and without the header file, I get no complaints and the compilation goes perfectly. The makefile looks like this:

#compiler
CC = gcc

#compiler flags
CFLAGS = -c -g -Wall
CFLAGS += -DGLUT_DISABLE_ATEXIT_HACK -D_STDCALL_SUPPORTED

#linker
LD = gcc

#linker libraries
#LDLIBS = -lglut -lGLU -lGL -luser
GLUTLIB=c:/Program/mingw/lib
GLUTINC=c:/Program/mingw/include/
LDFLAGS = -g -Wall -I$(GLUTINC) -pipe -fpic -DSHM
LDFLAGS += -L$(GLUTLIB)
LDFLAGS += -lglut32 -lGLU32 -lOpenGL32 -lgdi32 -luser32
LDFLAGS += -lm


labb3_4: main.o
$(LD) $(LDFLAGS) $? -o $@

main.o: main.c main.h
$(CC) $(CFLAGS) $< -o $@

clean:
rm -rf main.o mainThis problem is driving me nuts! Someone knows a fix for this?

RigidBody
10-08-2005, 11:54 AM
first of all: i think this should be in the developers forum :)

now to your problem: in your makefile the compiler flags include the
'-c' option, which means the source is only compiled but not linked.
if it is not linked, there cannot be any linker errors, but there will
be no exe-file, either.

scratty
10-08-2005, 11:54 AM
Perhaps I should move this thread to the development/windows forum.

scratty
10-08-2005, 11:58 AM
Funny! A simultaneous posting. What are the chances for that? :)

Well, I thought development was about development of OpenGL and not application specific development. Guess I got it all wrong :p . Sorry folx. (Please feel free to move this thread to the appropriate place.)

Yes. But I thought that you first tell the compiler to compile the source using "-c" and then let the compiler link the objects by not specifying any particular flag. Seems I'm missing something here. Hmmm...
So you mean I should skip the -c flag?

RigidBody
10-08-2005, 12:02 PM
it was not simultaneous posting. i was faster :D

anyway, welcome to the developers' forum...

RigidBody
10-08-2005, 12:06 PM
i think if you remove the '-c' in the makefile, you'll end with the
same error messages that you got on the command line.

hm...maybe you should try '-lopengl32' instead of '-lOpenGL32' and
'-lglu32' instead of '-lGLU32'

scratty
10-08-2005, 12:06 PM
Yeah, but it was nearly simultaneous. Simultanousness doesn't exist in the real world anyway ;) .

Thanx for the welcome.

Well that was my initial approach, but then I took a glance at some other compiler script which used mixed caps flags. Doesn't seem to matter, but I'll try again and see if ther's a change.

scratty
10-08-2005, 12:11 PM
Nope, same thing there.
Must be something else. *Sigh*
Don't get it. It works galantly compiling it with:
gcc -o <fname> <fname>.c -lglut32 -lglu32 -lopengl32 -luser32 -lgdi32

scratty
10-08-2005, 12:20 PM
Hmm... perhaps I should include the GL/glut.h in the header file instead.

scratty
10-08-2005, 12:48 PM
Ok. I finally succeeded to resolve the problem. Seems gcc didn't like the order of the flags upon linking.
Changing the line:

$(LD) $(LDFLAGS) $? -o $@ to:

$(LD) -o $@ $? $(LDFLAGS)did the trick indeed.

Weird. Makes me wonder why I didn't fiddle with the order of the flags before :rolleyes: . Hmm... seems gcc works slightly different from system to system :p . Thank you very much for trying to help me out though Rigid!!

(Now I know where to post these things in the future ;) .)