Search code examples
compilationubuntu-18.04emscriptenlameemcc

How to include library header when building with Emscripten?


I am trying to build codecbox.js on Ubuntu 18.04, which involves building FFmpeg with emcc. I have been stuck with the misleading libmp3lame >= 3.98.3 not found error. In my case, there is no problem with libmp3lame installation. After further investigation into FFmpeg's configure script, I found out that the following test file failed to compile with emcc:

#include <lame/lame.h>
#include <stdint.h>

long check_lame_set_VBR_quality(void) { return (long) lame_set_VBR_quality; }
int main(void) {
    int ret = 0;
    ret |= ((intptr_t)check_lame_set_VBR_quality) & 0xFFFF;
    return ret;
}

I get fatal error: 'lame/lame.h' file not found.

I found the header in /usr/include/lame so I tried compiling with emcc -I/usr/include. This removed the error but introduced plenty of other errors.

Then I read (for example here) that I should not use local system headers, which happens when I add option -I/usr/include.

So what is the proper way to ensure emcc finds my library header whilst using Emscripten bundled system headers provided within the SDK?


Solution

  • /usr/include/lame sounds like you are building it with the system installation. You are not supposed to build an emscriten module with any system-wide packages though. Imagine you are distributing the emscripten-compiled package to the web, not to someone else's desktop. You probably want to get the source of ffmpeg and other related libraries manually.