Elliot MacNeille
Elliot MacNeille

Reputation: 91

Can't get GMP lib compiling with Emscripten (2)

I'm a bit a newb. My system is OSX.

I've gotten emscripten working with SDL2 which is awesome. I compile with the command:

./emcc /Users/elliotmacneille/Projects/the\ simplifier/the\ simplifier/main.cpp -s USE_SDL=2 -s LEGACY_GL_EMULATION=1 -std=c++11 -o money99.html

from command line within the emscripten directory.

Now I wish to get GMP working with it. I have the header files, libgmp.a, and libgmp.10.dylib on my computer, but I dont know where to put them for emscripten. I have also made a gmp.js using emscripten, again not sure where to put it.

Whenever I try to compile I get this:

"fatal error: 
      'gmp.h' file not found
#include <gmp.h>
         ^
1 error generated."

Where should I put the header files and what library should I put where? I have no trouble compiling libgmp in Xcode, but I want to use emscripten.

Upvotes: 2

Views: 776

Answers (1)

JF Bastien
JF Bastien

Reputation: 6863

You have to tell the compiler where the library headers are using the -I command line option, and then which libraries to link to using the -l command line option. Something like:

emcc myfile.cpp -o myoutput.html -Lpath/to/gmp/include -lgmp

This isn't emscripten-specific: it's how C/C++ compilers like GCC and LLVM usually work. You didn't have to do this for SDL because it's special!

You won't be able to just used libgmp.a or libgmp.10.dylib though! Those target x86 (or at least they do on your Mac), and you want them to either be LLVM bitcode or JavaScript. There doesn't seem to be an easily-available gmp port, so the easiest is probably to build it yourself and link it into your application.

gmp usually builds with inline assembly but you can disable this from its build. It may be useful to check out how this was done for PNaCl inside of naclports, and doing the same thing for your own build.

Upvotes: 4

Related Questions