Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build static library that I can use later on while compiling code with emcc?

I'm building a third-party C library with emcc (version 1.38.38) in two steps:

  1. Building static library (using emar) with *.a extension
  2. Building a separate file with that static library.

Unfortunately I'm getting undefined symbols. What I've tried so far:

  • To build without emcc, using clang or gcc - everything working as expected
  • To check whether symbols are in the library built (they are)

It looks like I'm missing something very elementary which I yet failing to find an answer about, so I'm asking you:

How to build static library that I can use later on while compiling code with emcc?

like image 750
shabunc Avatar asked Sep 05 '25 16:09

shabunc


1 Answers

So, OK, I was stupid enough to ask this question, let me contribute to the community and confess what was the problem, may be it will help for someone else.

This code works:

 emcc -s WASM=1 -Isrc  main.c src/lib.a 

while this won't

 emcc -s WASM=1 -Isrc src/lib.a main.c 

The order is imporant so shame on me.

like image 181
shabunc Avatar answered Sep 09 '25 22:09

shabunc