Using libraries with emscripten - 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

What is the correct way to link 3rd party C++ libraries in Gradle?

I am currently trying to evaluate the use of Gradle C++ for a project that will have both Java and C++ components (with JNI to interface). I could just use CMake for the C++ portion, but then I would have 2 build systems which is less cleanly organized. As such, I prefer to use Gradle's C++ system in a multi-project build if it has the support that I need. The main thing that I can't find any detailed information (with code examples, etc.) is the linking of libraries. For Cmake, it is simple: use find_package or the pkg-config module. Every library (that I have tried to use) offers at least one of those systems. With Gradle, however, it only seems to document it for linking to C++ libraries that are built in the same project. What if, for example, I want to link to Vulkan, SFML, OpenGl, yaml-cpp, Boost, or any number of established and FOSS C++ libraries? The documentation also doesn't specify how to control dynamic or static linking.

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

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)