I'm trying to create a static library libGLApp.a that encapsulates some OpenGL functionality and would like to link some standard GL libs (lopengl32, lglu32) to my lib. I created a project with type "Win32 Static Lib" and entered the libs I desire into project's linker options. However, these options are completely ignored!
Linking my lib into an application confirms that functions from the desired libs have undefined references.
The problem occured using Dev-C++ 4.9.7.0. I also tried 4.9.9.2, but there another problem appeared: creating DLLs does not work, since macro to decide whether to use dllexport or dllimport when compiling is ignored: dllimport is always used. Therefore I switched back to 4.9.7.0.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2006-05-19
You cannot 'link' a static library to another static library. In fact the linker is not even used when creating static libraries, as can be seen from your compile log.
Libraries (or archives in GNU parlance) are simply collections of object code aggregated into a single container. The tool that does this is ar.exe (with some assistance from ranlib.exe). These tools are part of the GNU binutils documented here: http://www.gnu.org/software/binutils/manual/html_mono/binutils.html. As you can see from the documentation, it is possible to add the content of one archive to another. You may have to do this manually from the command line rather than have Dev-C++ do it (although you might try simply adding the archive to your project as you would a source file).
However I would be surprised if doing this with the openGL libraries did not have implications with respect to the GNU license (GPL or LGPL). The resulting library would be regarded as a derivitive work and would be subject to the same licensing if redistributed. It might be simpler and less problematic to leave them as separate entities.
As an aside I not that your library comprises a single object file. You get the greatest benefit from static libraries if you use as fine a granularity as possible, placing one function per module for example. This is because the linker links only those object modules necessary to resolve references in the application. By placing all your code in a single module, the linker must link everything including unused code. If the library is large, this could result in unnecessary code bloat.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'm trying to create a static library libGLApp.a that encapsulates some OpenGL functionality and would like to link some standard GL libs (lopengl32, lglu32) to my lib. I created a project with type "Win32 Static Lib" and entered the libs I desire into project's linker options. However, these options are completely ignored!
Compile log tells me:
rm -f main.o libGLApp.a
g++.exe -c main.cpp -o main.o -I"G:/DEV-CPP/include" -I"G:/DEV-CPP/include" -I"."
ar r libGLApp.a main.o
ranlib libGLApp.a
Linking my lib into an application confirms that functions from the desired libs have undefined references.
The problem occured using Dev-C++ 4.9.7.0. I also tried 4.9.9.2, but there another problem appeared: creating DLLs does not work, since macro to decide whether to use dllexport or dllimport when compiling is ignored: dllimport is always used. Therefore I switched back to 4.9.7.0.
You cannot 'link' a static library to another static library. In fact the linker is not even used when creating static libraries, as can be seen from your compile log.
Libraries (or archives in GNU parlance) are simply collections of object code aggregated into a single container. The tool that does this is ar.exe (with some assistance from ranlib.exe). These tools are part of the GNU binutils documented here: http://www.gnu.org/software/binutils/manual/html_mono/binutils.html. As you can see from the documentation, it is possible to add the content of one archive to another. You may have to do this manually from the command line rather than have Dev-C++ do it (although you might try simply adding the archive to your project as you would a source file).
However I would be surprised if doing this with the openGL libraries did not have implications with respect to the GNU license (GPL or LGPL). The resulting library would be regarded as a derivitive work and would be subject to the same licensing if redistributed. It might be simpler and less problematic to leave them as separate entities.
As an aside I not that your library comprises a single object file. You get the greatest benefit from static libraries if you use as fine a granularity as possible, placing one function per module for example. This is because the linker links only those object modules necessary to resolve references in the application. By placing all your code in a single module, the linker must link everything including unused code. If the library is large, this could result in unnecessary code bloat.
Clifford