Skip to content

Loading…

Converted Static Libraries do not include Library Functions #306

Closed
manuels opened this Issue · 1 comment

2 participants

@manuels

If you store this as calc_mean.c:

double mean(double a, double b) {
  return (a+b) / 2;
}

and compile it
clang -c calc_mean.c -o calc_mean.o -emit-llvm

then create a static library:
ar rcu libmean.a calc_mean.o

(check symbols:)
llvm-nm libmean.a
llvm-nm calc_mean.o

convert to js:
emcc -O0 --closure 0 libmean.a

resulted js code does not include the mean function (even when adding 'mean' and '_mean' to EXPORTED_FUNCTIONS in settings.js)

@kripken
Owner

This is a compiler/linker issue, it will happen with clang without emscripten too. Archives are linked differently than normal files by the compiler, only the relevant parts of them are linked in. Since there is no other code here, nothing is linked in.

So compiling the .o will work here, but not the .a

You actually need to put the other files in the right order too, with archives: clang main.cpp lib.a will work (if main uses lib stuff), but clang lib.a main.cpp will not.

@kripken kripken closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.