GCC SDL + GLEW linking errors - opengl

I have a static library in which I'm calling OpenGL extension functions via GLEW. As the project is being built in GCC (NetBeans 7.0), and GLEW's binaries are only shipped in Visual-C flavor, I have built GLEW (1.7.0) as a static library, with GCC. (I would also be interested why this is necessary, as GLEW seems to be pure C, in which ABI and cross-compiler compatibility isn't an issue AFAIK.)
In my static library I define GLEW_STATIC and NO_SDL_GLEXT as project preprocessor directives (-D), then I
#include "GL/glew.h"
#include "SDL/SDL.h"
The static library is then linked against in a (test) application, which also links against the following libraries, in the following order:
my_static_library
mingw32
glew32
opengl32
SDLmain
SDL
This setup gives me two undefined reference errors in my static library:
undefined reference to `_imp____glewGetStringi'
undefined reference to `_imp__glewInit'
Indeed, these are two calls made to GLEW functionality, in the static library. There are however other calls that the linker used to complain about (before -DGLEW_STATIC), yet seem to be ok now.
I wasn't able to improve the situation by swapping the order of linkage to opengl32 and glew32 (some more undef'd refs to wgl... calls). Furthermore, GLEW_STATIC (and NO_SDL_GLEXT) used to be defined in the test application but that has been removed and doesn't seem to matter.
Why do the remaining errors occur and what can I do to get rid of them, i.e. how can I use GLEW in GCC with SDL?

You library was built in such a way, as to link to the DLL version of GLEW - _imp____glewGetStringi and _imp__glewInit are import library symbols, i.e. the combination of defines resulted in the following line appearing when compiling;
extern __declspec(dllimport) PFNGLGETSTRINGIPROC __glewGetStringi;
This can happen if you don't define GLEW_STATIC while compiling your library (but you do; double check each object)
or
your version of GLEW has a bug in the headers. In GLEW 1.7.0 it works as expected.

Related

Error in emscripten when including glfw and opengl [duplicate]

I have just started using Emscripten and would like to start using GLFW and other libraries. I am completely lost on how to build, link, and use other libraries with Emscripten.
I have tried following the instructions on the Emscripten site but have they haven't helped me any.
http://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html#using-libraries
Is there any place with detailed instructions on how to use libraries with Emscripten? Or specifically GLFW?
Emscripten provide itself very few libraries. Those libraries are the minimum to get some OperativeSystem functionality on emscripten C++ code (audio, input, video)
libc: standard library for C
libc++: standard library for C++
SDL: SimpleDirectmediaLayer (SDL 1.X a opensource cross-platform project)
GLES2: OpenGL ES 2 API
GLFW: GLFW 2.X
For example, the standard way to include OpenGLES2 in Emscripten is:
#include <GLES2/gl2.h>
While to include GLFW:
#include <GL/glfw.h>
There's some crap in that, because if you want to use the more recent version of GLFW you just can't because Emscripten provides only 1 version of the library and you have to stick with that (unless Emscripten do a update for that and you update Emscripten).
You can compile libraries for emscripten only if that libraries can be compiled using one(or more) of the libraries listed above. (or if you know how to wrap javascript funciontalities and expose them through C interface)
Also, try to avoid templates only libraries when using Emscripten, they literally generate a lot of bloat code you could easily increase executable size by several MBs: This is a problem if you were already using Boost or UBLAS.
Since GLFW is not one of the libraries that are automatically linked, you should link it with:
-lglfw
You can find an example OpenGL project using Emscripten here:
https://github.com/QafooLabs/emscripten-opengl-example
you can inspect linker flags by opening the makefile

Using libraries with emscripten

I have just started using Emscripten and would like to start using GLFW and other libraries. I am completely lost on how to build, link, and use other libraries with Emscripten.
I have tried following the instructions on the Emscripten site but have they haven't helped me any.
http://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html#using-libraries
Is there any place with detailed instructions on how to use libraries with Emscripten? Or specifically GLFW?
Emscripten provide itself very few libraries. Those libraries are the minimum to get some OperativeSystem functionality on emscripten C++ code (audio, input, video)
libc: standard library for C
libc++: standard library for C++
SDL: SimpleDirectmediaLayer (SDL 1.X a opensource cross-platform project)
GLES2: OpenGL ES 2 API
GLFW: GLFW 2.X
For example, the standard way to include OpenGLES2 in Emscripten is:
#include <GLES2/gl2.h>
While to include GLFW:
#include <GL/glfw.h>
There's some crap in that, because if you want to use the more recent version of GLFW you just can't because Emscripten provides only 1 version of the library and you have to stick with that (unless Emscripten do a update for that and you update Emscripten).
You can compile libraries for emscripten only if that libraries can be compiled using one(or more) of the libraries listed above. (or if you know how to wrap javascript funciontalities and expose them through C interface)
Also, try to avoid templates only libraries when using Emscripten, they literally generate a lot of bloat code you could easily increase executable size by several MBs: This is a problem if you were already using Boost or UBLAS.
Since GLFW is not one of the libraries that are automatically linked, you should link it with:
-lglfw
You can find an example OpenGL project using Emscripten here:
https://github.com/QafooLabs/emscripten-opengl-example
you can inspect linker flags by opening the makefile

SFML2 static linking error with mingw32: undefined references

I am using Code::Blocks on 64bit Windows 7, MinGW 4.7.1.
I'm trying to get SFML 2.1 to work with MingW in codeblocks, but it's causing problems.
when i try to compile i get these errors:
undefined reference to _imp___ZN2sf6StringC1EPKcRKSt6locale
undefined reference to _imp___ZN2sf9VideoModeC1Ejjj
...
I'm linking the following libraries:
sfml-graphics
sfml-window
sfml-system
What am I doing wrong? The errors say undefined reference, but I have already follow these instructions step by step.
When trying to link the static version of the library, you'll essentially have to use the static version of the headers as well (otherwise you're essentially looking for the references at the wrong place (more specifically: with the wrong format/decoration)).
As such, when linking the static version, always make sure that SFML_STATIC is defined before you include any SFML header.
Also, make sure to link the static version of the libraries (with a -s suffixed).
Static SFML
Define SFML_STATIC.
Link to sfml-system-s, sfml-window-s, sfml-graphics-s, etc. (or their debug versions).
Dynamic SFML
Do not define SFML_STATIC.
Link to * sfml-system*, sfml-window, sfml-graphics, etc. (or their debug versions).

Eclipse-CDT/C++: Undefined reference-errors although right .o-files are created and passed to the linker

At first: I am not using an already compiled library.
Here's the situation: I've got a C++ project in eclipse CDT that has a folder structure like this:
project
somefoldername
src
include
library
src
include
somefoldername/src and library/src are defined as source folders and somefoldername/include as well as library/include are defined as include folders (under C/C++ General->Paths and Symbols, which also affects the compilers -I option).
The "library" folder contains the source code of a library used by my own code (which can be found in "somefolder"). Well, compiling of the whole project works fine, but linking crashes with a whole bunch of "undefined reference" errors in the library's source.
The undefined reference errors occur, although *.o-files are created in which the missing functions should be found - and also are passed to the linker afterwards.
What am I doing wrong?
Edit: Updated to current configuration and the attempts to solve the problem.
Edit2: The accepted answer helped me out a bit, but the biggest problem seemed to be the "linking everything at once"-policy followed by eclipse. I went to autoconf and built the library first, before linking it to the main application. Although it's more work, it's a cleaner approach.
Three possibilities:
1) The "undefined" symbols aren't actually in your library
This is unlikely, but you can verify using the "nm" Linux command
2) You aren't setting the library search path ("dash-big-L") correctly in Eclipse
link static lib in eclipse cdt
... or ...
3) Perhaps you built the library with "C" linkage, but your program is using C++ linkage (or vice versa). If you're using the "C" (gcc") compiler, or have any "*.c" source files, then make sure all functions have prototypes in your .h header, and all prototypes use "extern "C"" as appropriate:
& http://msdn.microsoft.com/en-us/library/0603949d%28v=vs.80%29.aspx

GLEW and Freeglut won't work together?

I am trying to use geometry shaders in my OpenGL application that is currently using Freeglut, and I am trying to use GLEW to do that because as I understand it, the geometry shader functionality is in an extension. My include order is as follows:
#define GLEW_STATIC
#include <glew.h>
#include "freeglut.h"
However when I do this I get lots of linker errors like the following:
error LNK2001: unresolved external symbol ___glewAttachShader
I do not receive any errors when I only use the basic OpenGL functionality (that it, things that are not in the extensions) so I know that the compiler is finding all the "basic" libraries like glu32 etc. I am using Visual Studio 2008. Any suggestions?
It's a linker error that says it did not find a glew entrypoint.
Link against the glew library (you did not see the error before because you did not use any extension, I assume).
Edit:
Actually, this is directly related to your usage of "GLEW_STATIC".
From the GLEW page:
On Windows, you also have the option of adding the supplied project file glew_static.dsp to your workspace (solution) and compile it together with your other projects. In this case you also need to change the GLEW_BUILD preprocessor constant to GLEW_STATIC when building a static library or executable, otherwise you get build errors.
What this says is that it is your responsibility to build and include the glew source files when you use the GLEW_STATIC setup.