linking issue with freeglut (on x86 win)

Hi,

I’m trying to compile a piece of code with pgcc v10.9-0 (32 bit) on a x86 Windows system. The code uses the freeglut (v2.6.0) library. I’ve obtained the freeglut .lib files compiling the source code available from the reference site (http://freeglut.sourceforge.net/) with the MS Visual Studio 2008 suite. Unfortunately I have a problem at the linking stage.

Here the compiler output:

pgcc -ta=nvidia,time -mp -L../../code/freeglut ./obj/algeb.o ./obj/algorithm.o ./obj/dynarr.o ./obj/param.o ./obj/random.o ./obj/rply.o ./obj/s
ampler.o ./obj/samplerply.o ./obj/saver.o ./obj/saverply.o ./obj/soam.o ./obj/soam2d.o ./obj/test.o ./obj/viewer.o -o ./bin/soam-parallel
viewer.o : error LNK2019: unresolved external symbol _imp_glutInitDisplayMode@4 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutInitWindowSize@8 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutInitWindowPosition@8 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutDisplayFunc@4 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutReshapeFunc@4 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutMouseFunc@4 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutMotionFunc@4 referenced in function viewersetup
viewer.o : error LNK2019: unresolved external symbol _imp_glutKeyboardFunc@4 referenced in function viewersetup
...
viewer.o : error LNK2019: unresolved external symbol _imp_glOrtho@48 referenced in function viewerlaunch
viewer.o : error LNK2019: unresolved external symbol _imp_glPopMatrix@0 referenced in function viewerlaunch
viewer.o : error LNK2019: unresolved external symbol _imp_glRasterPos2f@8 referenced in function viewerlaunch
viewer.o : error LNK2019: unresolved external symbol glutBitmap8By13 referenced in function viewerlaunch
viewer.o : error LNK2019: unresolved external symbol _imp_glutBitmapCharacter@8 referenced in function viewer_launch
./bin/soam-parallel.exe : fatal error LNK1120: 45 unresolved externals

And here the makefile I use:

CC = pgcc
CCFLAGS = -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast
LDFLAGS = -ta=nvidia,time -mp -L../../code/freeglut/lib
			 
BINDIR = ./bin
OBJDIR = ./obj

INCDIR = -I../../code/soam-parallel/source -I../../code/freeglut/inc
		 
SRCDIR = ../../code/soam-parallel/source

SRCFILES := $(wildcard $(SRCDIR)/*.c)
OBJFILES := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(wildcard $(SRCDIR)/*.c))

EXEC = soam-parallel

all : init $(EXEC)
	
init :
	mkdir -p $(OBJDIR) $(BINDIR)	
	
$(EXEC) : $(OBJFILES)
	$(CC) $(LDFLAGS) $(OBJFILES) -o $(BINDIR)/$(EXEC)
	
$(OBJDIR)/%.o : $(SRCDIR)/%.c
	$(CC) $(CCFLAGS) $(INCDIR) -c $< -o $@
	
clean :
	rm -fr $(OBJDIR)/* $(BINDIR)/*

Can anyone give some advice in order to find a solution?

Cheers
A.

P.S. The same code compiles (and runs) correctly on the same system when I use a Linux distribution (namely Ubuntu 10.04) with the freeglut library downloaded from the official repositories, and simply specifying the compiler options -lglut -lGLU -lGL.

Hi A.

pgcc -ta=nvidia,time -mp -L../../code/freeglut ./obj/algeb.o ./obj/algorithm.o ./obj/dynarr.o ./obj/param.o ./obj/random.o ./obj/rply.o ./obj/s
ampler.o ./obj/samplerply.o ./obj/saver.o ./obj/saverply.o ./obj/soam.o ./obj/soam2d.o ./obj/test.o ./obj/viewer.o -o ./bin/soam-parallel

Looks like you’re missing the Glut libraries on your link line. What are their names? If they are something like “libglut.lib”, then you can just add “-lglut”. If they are like “glut.lib” then you need to add the fully qualified filename (i.e include the full DOS PATH).

Since the symbol names begin with “_imp” the libraries are most likely DLLs. In this case you may need to compile and link with the “-Mdll” flag as well.

Hope this helps,
Mat

Hi Mat

Thank you for your quick response. Nevertheless, I’ve done what you have suggested, but still the code doesn’t compile. I obtain the same error at the linking stage.

Here the (complete) compiler output:

pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/algeb.c -o obj/algeb.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/algorithm.c -o obj/algorithm.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/dynarr.c -o obj/dynarr.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/param.c -o obj/param.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/random.c -o obj/random.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/rply.c -o obj/rply.o
PGC-W-0043-Redefinition of symbol, va_list (j:\PROGRA~1\PGI/win32/10.9/include\stdarg.h: 37)
PGC/x86 Windows 10.9-0: compilation completed with warnings
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/sampler.c -o obj/sampler.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/sampler_ply.c -o obj/sampler_ply.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/saver.c -o obj/saver.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/saver_ply.c -o obj/saver_ply.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/soam.c -o obj/soam.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/soam2d.c -o obj/soam2d.o
soam2d_find_winners:
    790, Generating copyout(soam_distances[:soam_cuda_real_threads*3-1])
         Generating copyout(soam_indices[:soam_cuda_real_threads*3-1])
         Generating copyin(soam_landmarks[:vertices*4-1])
         Generating copyin(soam_samples[:soam_cuda_real_threads*4-1])
         Generating compute capability 1.3 binary
    799, Loop is parallelizable
         Accelerator kernel generated
        799, #pragma acc for parallel(32), vector(32)
             Non-stride-1 accesses for array 'soam_distances'
             Non-stride-1 accesses for array 'soam_indices'
             CC 1.3 : 18 registers; 20 shared, 52 constant, 0 local memory bytes; 25 occupancy
    810, Scalar last value needed after loop for 'third_best_index' at line 843
         Loop carried scalar dependence for 'third_best_distance' at line 835
         Scalar last value needed after loop for 'third_best_distance' at line 847
         Loop carried scalar dependence for 'second_best_index' at line 821
         Loop carried scalar dependence for 'second_best_index' at line 830
         Scalar last value needed after loop for 'second_best_index' at line 842
         Loop carried scalar dependence for 'second_best_distance' at line 822
         Loop carried scalar dependence for 'second_best_distance' at line 829
         Loop carried scalar dependence for 'second_best_distance' at line 831
         Scalar last value needed after loop for 'second_best_distance' at line 846
         Loop carried scalar dependence for 'best_index' at line 824
         Scalar last value needed after loop for 'best_index' at line 841
         Loop carried scalar dependence for 'best_distance' at line 820
         Loop carried scalar dependence for 'best_distance' at line 825
         Scalar last value needed after loop for 'best_distance' at line 845
         Inner sequential loop scheduled on accelerator
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/test.c -o obj/test.o
pgcc -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll -I../../code/soam-parallel/source -IJ:/DATA/stage/source/workspace
/code/freeglut/inc -c ../../code/soam-parallel/source/viewer.c -o obj/viewer.o
PGC-W-0043-Redefinition of symbol, va_list (j:\PROGRA~1\PGI/win32/10.9/include\stdarg.h: 37)
PGC/x86 Windows 10.9-0: compilation completed with warnings
pgcc -ta=nvidia,time -mp -Mdll -LJ:/DATA/stage/source/workspace/code/freeglut/lib/freeglut.lib -LJ:/DATA/stage/source/workspace/code/freeglut/lib/free
glut.dll  ./obj/algeb.o  ./obj/algorithm.o  ./obj/dynarr.o  ./obj/param.o  ./obj/random.o  ./obj/rply.o  ./obj/sampler.o  ./obj/sampler_ply.o  ./obj/s
aver.o  ./obj/saver_ply.o  ./obj/soam.o  ./obj/soam2d.o  ./obj/test.o  ./obj/viewer.o -o ./bin/soam-parallel
viewer.o : error LNK2019: unresolved external symbol __imp__glutInitDisplayMode@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutInitWindowSize@8 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutInitWindowPosition@8 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutDisplayFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutReshapeFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutMouseFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutMotionFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutKeyboardFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutSpecialFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutTimerFunc@12 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutIdleFunc@4 referenced in function _viewer_setup
viewer.o : error LNK2019: unresolved external symbol __imp__glutMainLoop@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutAddMenuEntry@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutAttachMenu@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutSwapBuffers@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutPostRedisplay@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutGetModifiers@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol _gluLookAt@72 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPointSize@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glDisable@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutGet@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPolygonMode@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glVertex2i@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp____glutCreateMenuWithExit@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPushMatrix@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glOrtho@48 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPopMatrix@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glRasterPos2f@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol _glutBitmap8By13 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glutBitmapCharacter@8 referenced in function _viewer_launch
./bin/soam-parallel.exe : fatal error LNK1120: 45 unresolved externals

And here the new makefile

CC = pgcc
CCFLAGS = -ta=nvidia,time -Minfo=loop,accel,vect,mp -Msafeptr -Mipa=fast -mp -fast -Mdll

GLUTDIR = J:/DATA/stage/source/workspace/code/freeglut

LDFLAGS = -ta=nvidia,time -mp -Mdll \
		  -L$(GLUTDIR)/lib/freeglut.lib \
		  -L$(GLUTDIR)/lib/freeglut.dll
			 
BINDIR = ./bin
OBJDIR = ./obj

INCDIR = -I../../code/soam-parallel/source \
		 -I$(GLUTDIR)/inc
		 
SRCDIR = ../../code/soam-parallel/source

SRCFILES := $(wildcard $(SRCDIR)/*.c)
OBJFILES := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(wildcard $(SRCDIR)/*.c))

EXEC = soam-parallel

all : init $(EXEC)
	
init :
	mkdir -p $(OBJDIR) $(BINDIR)	
	
$(EXEC) : $(OBJFILES)
	$(CC) $(LDFLAGS) $(OBJFILES) -o $(BINDIR)/$(EXEC)
	
$(OBJDIR)/%.o : $(SRCDIR)/%.c
	$(CC) $(CCFLAGS) $(INCDIR) -c $< -o $@
	
clean :
	rm -fr $(OBJDIR)/* $(BINDIR)/*

Any suggestions ?

Cheers
A.

pgcc -ta=nvidia,time -mp -Mdll -LJ:/DATA/stage/source/workspace/code/freeglut/lib/freeglut.lib -LJ:/DATA/stage/source/workspace/code/freeglut/lib/free 
glut.dll  ./obj/algeb.o  ./obj/algorithm.o  ./obj/dynarr.o

Remove the “-L” from the library name. “-L” tells the linker the search path for libraries, not the library name. Also, you don’t need the DLL on the link line since “freeglut.lib” is the import library for the “freeglut.dll”.

Something like:

pgcc -ta=nvidia,time -mp -Mdll J:/DATA/stage/source/workspace/code/freeglut/lib/freeglut.lib ./obj/algeb.o  ./obj/algorithm.o  ./obj/dynarr.o

Hope this helps,
Mat

Hi Mat

Thank you again for your help. Following your suggestions something has changed in the compiler output, but still I have some linking problems:

pgcc -ta=nvidia,time -mp -Mdll J:/DATA/stage/source/workspace/code/freeglut/lib/freeglut.lib  ./obj/algeb.o  ./obj/algorithm.o  ./obj/dynarr.o  ./obj/
param.o  ./obj/random.o  ./obj/rply.o  ./obj/sampler.o  ./obj/sampler_ply.o  ./obj/saver.o  ./obj/saver_ply.o  ./obj/soam.o  ./obj/soam2d.o  ./obj/tes
t.o  ./obj/viewer.o -o ./bin/soam-parallel
viewer.o : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol _gluLookAt@72 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPointSize@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glDisable@4 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPolygonMode@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glVertex2i@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPushMatrix@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glOrtho@48 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glPopMatrix@0 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol __imp__glRasterPos2f@8 referenced in function _viewer_launch
viewer.o : error LNK2019: unresolved external symbol _glutBitmap8By13 referenced in function _viewer_launch
./bin/soam-parallel.exe : fatal error LNK1120: 23 unresolved externals

Any idea how to solve this ?

Cheers
A.

Hi A.

Notice that the symbols that got resolved all start with “glut” while the ones that remain start with “gl” or “glu”? This indicates that you’ll need to find a Windows GLU and GL libraries and add them to your link line.

These libraries should resolve all but one of the references. The symbol “_glutBitmap8By13” seems to be declared differently than the others (.i.e it’s without the “imp” tag indicating that the symbol is found in a DLL import library). You’ll need to determine where this symbol can be found and add the appropriate library or object.

Hope this helps,
Mat

Many thanks for your help, Mat.

I linked the missing .lib files (those about the “gl” and “glu” references), namely the GlU32.lib and the OpenGL32.lib and now I’m able to compile correctly.

I temporarily resolved the “_glutBitmap8By13” symbol replacing the GLUT_BITMAP_8_BY_13 constant with its definition ((void *)0x0003).

But now, I have a new problem. My .exe file requires a .dll file (msvcr100.dll) to run, but if I try to add it in the same folder where i placed the .exe file, the application still crashes (saying me that it requires the .dll file). In the case of freeglut.dll I don’t have this issue.

Any suggestions ?

Cheers
A.

Hi A.

The directories that contain the DLLs need to be in your PATH or in a default directory (like C:\Windows\System). Though, in this particular case you may want to instead install the Microsoft Visual C++ 2010 Redistributable Package instead. It will contain the latest version of msvcr100.dll and install it in a default location.

The 64-bit Package can be found at:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bd512d9e-43c8-4655-81bf-9350143d5867

The 32-bit package can be found at: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84

Hope this helps,
Mat