Error in emscripten when including glfw and opengl [duplicate] - c++

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

Related

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

Running OpenGL without installing?

I am writing an OpenGL based game. It includes just these two libraries: glew, glfw3. In order to run it the user must obviously have OpenGL installed, an assumption which I'd like to bypass.
I've gathered all the appropriate binaries inside the game directory and tried linking to these libraries locally but the compiler claims undefined reference to all their functions. Am I doing something wrong or is it just impossible? I'm using Windows but it fails on Linux for the same reason.
OpenGL is not a library you install, it's an API that's implemented as part of the driver. Your compiler complaining about symbols not resolving is completely unrelated to the situation on the end user's computer. And in your case it simply sounds that you did not tell the compiler / linker which libraries and API interfaces to link into your program binary; your compiler is hence complaining, that some of the internal references don't redolve.
So here it goes: OpenGL is not something you ship with your program, it's part of the graphics drivers and your program must use whatever OpenGL version is installed on the user's machine. For this you dynamically link against libGL.so by passing the compiler-linker option -lGL.
GLEW is a helper library that post-loads dynamically all OpenGL functions not found in the system OpenGL ABI, which hence are not exported through the public symbol table of libGL.so. Rather they're to be loaded dynamically using glXGetProcAddress – a rather tedious task. Be advised that GLEW has some serious issues when it comes to OpenGL-3 and later core profiles.
GLFW is a simplistic framework library for setting up a window having an OpenGL context.
GLEW and GLFW are safe to link statically with your program, and I recommend you do that. Instead of using the -l… flag, add libGLEW.a and libGLFW.a to the list of source files / compilation units to be linked.

Include OpenGL Libraries in C++, Windows 7

I am reading through a "Getting Started with OpenGL" tutorial and I came across this text:
"If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you're building a 64-bit executable. The "32" part is meaningless). Visual Studio, and most Windows compilers, come with this library."
I am just trying to write my source files using vim, I don't want to use an IDE like VS, and from my understanding the OpenGL libraries come with Windows 7 (correct me if I'm wrong). After this point the article doesn't really go into any more detail about how to include the OpenGL libraries, and my real question is, how do I include and use the OpenGL libraries in my source files?
Is it as simple as writing #include <name of lib> or do I need to do something else with my Programming environment like editing my path variables?
Edit: I'm using the MinGW g++/gcc compiler
To get access to the include files, you need a special support library. There are more than one of these, but I would recommend GLEW. You can find the GLEW interface at http://glew.sourceforge.net/.
The reason for this is that only a very old version of OpenGL headers are available as default on Windows. The newer interface is available indirectly; you have to ask for function addresses. This is however done by GLEW for you.
So you only have to include < GL/glew.h>, and do some initialization with glewInit();
This is compatible with both Linux and Windows, especially as you use MinGW. When linking, I use the following:
MY_LIBS =
-lglew32
-lopengl32
-lWs2_32 -lole32 -lcomctl32 -lgdi32 -lcomdlg32 -luuid
I can recommend the use of a generic makefile, see http://sourceforge.net/projects/gcmakefile/
Notice that you also have to setup a context for OpenGL, before initializing GLEW. This is done differently depending on the environment. It is done when you open a window. For portable libraries, I can recommend the glfw library or freeglut.

OpenGL libraries

From OpenGL wiki:
"For most libraries you are familiar with, you simply #include a header file, make sure a library is linked into your project or makefile, and it all works. OpenGL doesn't work that way."
I work on Windows 64 and I need OpenGL to use it in C++ application. What library I should use? Does microsoft provide its implementation ( I use MinGW, I do not have MS Visual C++ )?
The one that comes with your GPU drivers that you have installed on your machine, Microsoft also provides a software layer for OpenGL emulation but it's stuck at the version 1.1 and it's really old and useless.
What library should I use?
I recommend using GLEW for easy access to functions of OpenGL 1.2 and higher, GLM for mathematics, and one of these image loading libraries.
Does microsoft provide its implementation (of OpenGL)?
Microsoft provides you with the necessary header files and library files to access the OpenGL API. However, in order to use OpenGL functions of version 1.2 and higher, you must use extensions. GLEW does this implicitly for you.
Take a look at glew. It loads needed extensions and core functions.

how can I use static library build by different version of mingw?

Greetings,
I am facing a complicated situation about using a static library under windows.
The static library is build by a specific version of mingw which is bundled with Eiffel studio. Since Eiffel studio uses mingw to create its output as a static lib, I have no control over this configuration.
If I try to use this static library with Eclipse CDT which is using a more recent version of mingw, then I can't compile my project. This is because I have to provide -l options to various libraries like winsock, and it appears due to difference between versions of compilers generating static library and my code, this does not work.
If I force Eclipse to use the same mingw directory that comes with Eiffel studio, the one that compiled the static lib, then I can compile my code (there are some other issues here though)
I do not want to constrain my c++ development just because a static library is build with a particular version of mingw.
So how can I use this static library from my own mingw version? This is windows xp btw..
Best Regards
Seref
Though I don't have a lot of information here is what I would do:
Try to compile with the newer version of mingw and see if you can make it work. Errors are very important in this case (you should check also the mingw manual/mailing lists/forums for finding about the compatibility between mingw versions
Separate the library from the program and wrap all its functionality - to avoid different incompatible compilation flags (you could create a different library - even a DLL and call your new functions (wrappers for some library functions)
Decide what part of the project is mandatory - the part with the library or the rest of the code
If the library is mandatory I would compile the code with that version of mingw
Else I would try to find an equivalent for that library or eliminate it
Others option may be available but this is what I would do (in this order)