From: Andreas V. <li...@br...> - 2006-09-18 22:05:09
|
Hi, I've a application that uses FreeGLUT (2.4.0) on Linux without any problems. Now I've some problems porting this application to Windows. Because I don't own VC++ I used Dev-C++ to compile a library for Windows. Project was "static library" and -DFREEGLUT_STATIC. The libfreeglut.a is build without any problems. [1] But see if I link this example to freeglut: #include <GL/freeglut.h> int main () { glutMainLoop(); return 0; } $ gcc -I/c/programme/dev-cpp/include -L/c/programme/dev-cpp/lib freeglut_test.c -o test -lfreeglut C:/DOKUME~1/andreas/LOKALE~1/Temp/ccugaaaa.o(.text+0x2b):freeglut_test.c: undefined reference to `_imp__glutMainLoop@0' collect2: ld returned 1 exit status Why does this happen and how could I solve this problem? regards Andreas [1] The linked library if usefull for your answer: http://brachttal.net/tmp/libfreeglut.a |
From: Joe K. <kr...@ni...> - 2006-09-19 17:23:28
|
The problem is object code in Win32 links differently to static libraries than to dynamic libraries. The linker is looking for a symbol with an _imp__ prefix. That means your code was compiled expecting to be linked with a dynamic library, but you are linking against a static library. The whole design is a major annoyance, and means recompiling everything just to switch between static and dynamic libraries. A DLL import symbol is declared by __declspec(dllimport). The freeglut header allows you to avoid this attribute by defining FREEGLUT_STATIC. If you are new to Win32, you will find there are a lot of Win32-specific things. For example, Win32 programmers like to put library pragmas in the headers, which sets a flag to link in libraries automatically. It can cause problems if you are trying to link in an explicit library file, when another one is already in your link path. Joe Andreas Volz wrote: > Hi, > > I've a application that uses FreeGLUT (2.4.0) on Linux without any > problems. Now I've some problems porting this application to Windows. > > Because I don't own VC++ I used Dev-C++ to compile a library for > Windows. Project was "static library" and -DFREEGLUT_STATIC. The > libfreeglut.a is build without any problems. [1] > > But see if I link this example to freeglut: > > #include <GL/freeglut.h> > > int main () > { > glutMainLoop(); > return 0; > } > > $ gcc > -I/c/programme/dev-cpp/include -L/c/programme/dev-cpp/lib > freeglut_test.c -o test -lfreeglut > C:/DOKUME~1/andreas/LOKALE~1/Temp/ccugaaaa.o(.text+0x2b):freeglut_test.c: > undefined reference to `_imp__glutMainLoop@0' collect2: ld returned 1 > exit status > > Why does this happen and how could I solve this problem? > > regards > Andreas > > [1] The linked library if usefull for your answer: > http://brachttal.net/tmp/libfreeglut.a > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Freeglut-developer mailing list > Fre...@li... > https://lists.sourceforge.net/lists/listinfo/freeglut-developer |
From: Andreas V. <li...@br...> - 2006-09-19 20:50:09
|
Am Tue, 19 Sep 2006 13:23:21 -0400 schrieb Joe Krahn: > The problem is object code in Win32 links differently to static > libraries than to dynamic libraries. The linker is looking for a > symbol with an _imp__ prefix. That means your code was compiled > expecting to be linked with a dynamic library, but you are linking > against a static library. The whole design is a major annoyance, and > means recompiling everything just to switch between static and > dynamic libraries. > > A DLL import symbol is declared by __declspec(dllimport). The > freeglut header allows you to avoid this attribute by defining > FREEGLUT_STATIC. > > If you are new to Win32, you will find there are a lot of > Win32-specific things. For example, Win32 programmers like to put > library pragmas in the headers, which sets a flag to link in > libraries automatically. It can cause problems if you are trying to > link in an explicit library file, when another one is already in your > link path. I compiled freeglut with -DFREEGLUT_STATIC. But I missed to add this define to my example. Now it works (nearly). There's still the same problem as with (real) GLUT. I need to link against -lfreeglut -lglu32 -lopengl32 -lwinmm -lgdi32 in exact this order to get no unresolved symbols. I tried to compile freeglut with -lwinmm and -lgdi32 to avoid this, but no change. I don't like linking all my apps to -lwinmm and -lgdi32. This troubles all my autotool scripts that work for Linux. So why is this needed on windows and how could I avoid it? regards Andreas |
From: Joe K. <kr...@ni...> - 2006-09-19 23:29:07
|
I think that a Linux static library can include a list of dependent libraries, but that Win32 cannot. So, adding '-lwinmm -lgdi32' when building the static library won't help. I'm not sure how to avoid it. If gcc honors Microsofts #pragma (lib) stuff, then you could include those pragmas in the freeglut header, so that the header, raether than the static library itself, defines which extra dependent libraries must be linked in. I'll try a few experiments tonight using gcc in Cygwin. Joe Andreas Volz wrote: > Am Tue, 19 Sep 2006 13:23:21 -0400 schrieb Joe Krahn: > > >>The problem is object code in Win32 links differently to static >>libraries than to dynamic libraries. The linker is looking for a >>symbol with an _imp__ prefix. That means your code was compiled >>expecting to be linked with a dynamic library, but you are linking >>against a static library. The whole design is a major annoyance, and >>means recompiling everything just to switch between static and >>dynamic libraries. >> >>A DLL import symbol is declared by __declspec(dllimport). The >>freeglut header allows you to avoid this attribute by defining >>FREEGLUT_STATIC. >> >>If you are new to Win32, you will find there are a lot of >>Win32-specific things. For example, Win32 programmers like to put >>library pragmas in the headers, which sets a flag to link in >>libraries automatically. It can cause problems if you are trying to >>link in an explicit library file, when another one is already in your >>link path. > > > I compiled freeglut with -DFREEGLUT_STATIC. But I missed to add this > define to my example. Now it works (nearly). There's still the same > problem as with (real) GLUT. I need to link against -lfreeglut -lglu32 > -lopengl32 -lwinmm -lgdi32 in exact this order to get no unresolved > symbols. I tried to compile freeglut with -lwinmm and -lgdi32 to avoid > this, but no change. > > I don't like linking all my apps to -lwinmm and -lgdi32. This troubles > all my autotool scripts that work for Linux. So why is this needed on > windows and how could I avoid it? > > regards > Andreas > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Freeglut-developer mailing list > Fre...@li... > https://lists.sourceforge.net/lists/listinfo/freeglut-developer |
From: Andreas V. <li...@br...> - 2006-09-20 21:00:11
|
Am Tue, 19 Sep 2006 19:28:59 -0400 schrieb Joe Krahn: > I think that a Linux static library can include a list of dependent > libraries, but that Win32 cannot. So, adding '-lwinmm -lgdi32' when > building the static library won't help. > > I'm not sure how to avoid it. If gcc honors Microsofts #pragma (lib) > stuff, then you could include those pragmas in the freeglut header, > so that the header, raether than the static library itself, defines > which extra dependent libraries must be linked in. > > I'll try a few experiments tonight using gcc in Cygwin. Did you find the reason why this happens? BTW: I use mingw and msys instead of cygwin. regards Andreas |
From: Joe K. <kr...@ni...> - 2006-09-21 16:37:33
|
I didn't get a chance to look at it. Just to understand the behavior you would like to see, are you linking with just GLUT/FreeGLUT in Linux, and that is automatically pulling in all dependent graphics libraries, like libX11, even when it's a static lib? In other words, are you hoping that simple cross-platform GLUT source code should only need to link against GLUT, and no other platform-dependent libs? Joe Andreas Volz wrote: > Am Tue, 19 Sep 2006 19:28:59 -0400 schrieb Joe Krahn: > >> I think that a Linux static library can include a list of dependent >> libraries, but that Win32 cannot. So, adding '-lwinmm -lgdi32' when >> building the static library won't help. >> >> I'm not sure how to avoid it. If gcc honors Microsofts #pragma (lib) >> stuff, then you could include those pragmas in the freeglut header, >> so that the header, raether than the static library itself, defines >> which extra dependent libraries must be linked in. >> >> I'll try a few experiments tonight using gcc in Cygwin. > > Did you find the reason why this happens? BTW: I use mingw and msys > instead of cygwin. > > regards > Andreas > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Freeglut-developer mailing list > Fre...@li... > https://lists.sourceforge.net/lists/listinfo/freeglut-developer |
From: Andreas V. <li...@br...> - 2006-09-21 18:20:07
|
Am Thu, 21 Sep 2006 12:37:27 -0400 schrieb Joe Krahn: > I didn't get a chance to look at it. > > Just to understand the behavior you would like to see, are you > linking with just GLUT/FreeGLUT in Linux, and that is automatically > pulling in all dependent graphics libraries, like libX11, even when > it's a static lib? In other words, are you hoping that simple > cross-platform GLUT source code should only need to link against > GLUT, and no other platform-dependent libs? Yes. For example I link a simple GLUT (FreeGLUT) application on Linux with this Makefile: INCLUDE = -I/usr/include/GL LIBDIR = -L. -L/usr/X11R6/lib COMPILERFLAGS = -Wall CC = gcc CFLAGS = $(COMPILERFLAGS) $(INCLUDE) LIBRARIES = -lglut -lGL -lGLU GLUTdemo : example1.o $(CC) $(CFLAGS) -o example1 $(LIBDIR) example1.o $(LIBRARIES) clean: @rm -rf *.o *~ example1 As you see it uses only -lglut -lGL -lGLU. > even when > it's a static lib? Hm, this is a good question! I do not often link static on Linux. I should try it. And perhaps I should try to build a dynamic freeglut library on win32. But I don't think this is the problem. My (real) GLUT library here is also a DLL and I need to link against -lwinmm and -lgdi32. regards Andreas |
From: Joe K. <kr...@ni...> - 2006-09-24 21:18:02
|
The way library pragmas work in MS-Windows is that the compiler generates a special object-file directive in a special ".drective" section. I think that you can build a static library that automatically pulls in dependent libraries by simply including object files containing these directives. The problem is that Win32 gcc appears not support either the #pragma or the .drective for library dependencies. SInce this is the way MS-Win32 deals with dependencies, it would be nice if gcc would support it. I suspect they don't just because the design is 'ugly'. The alternatives are to explicitly include link flags, or use a non-MS library format, for example a 'libtool' library. This is probably one reason why many cross-platform libs include a script to emit linker flags, like "freetype-config --libs". Joe |
From: Sven P. <sve...@ae...> - 2006-10-21 12:37:13
|
Am Donnerstag, 21. September 2006 20:15 schrieb Andreas Volz: > Am Thu, 21 Sep 2006 12:37:27 -0400 schrieb Joe Krahn: > > I didn't get a chance to look at it. > > > > Just to understand the behavior you would like to see, are you > > linking with just GLUT/FreeGLUT in Linux, and that is automatically > > pulling in all dependent graphics libraries, like libX11, even when > > it's a static lib? In other words, are you hoping that simple > > cross-platform GLUT source code should only need to link against > > GLUT, and no other platform-dependent libs? > [...] > As you see it uses only -lglut -lGL -lGLU. The Makefile you've shown results in dynamically linking your executable against GL/GLU/freeglut. If your Linux distro gets things right (earlier Gentoo distros had a bug in this area IIRC), a simple "-lglut" should suffice, as dynamic libs record their dependencies. You can e.g. use "ldd" on "libglut.so" to see what freeglut depends on. > > even when > > it's a static lib? > > Hm, this is a good question! I do not often link static on Linux. I > should try it.[...] Linking things statically is completely different story, so you have to mention all libraries and the transitive hull of their dependencies in the right order in the linker commandline. Just adding "-static" to the GCC invocation is not enough. Furthermore, platforms differ quite a lot in the dynamic/static linking area, and if you want to write portable SW without going crazy because of this, libtool is your friend... Cheers, S. |