Hello,
I am trying to build a shared library with emscripten that depends from a static library.
I am not able to do it.
I get this error:
exception thrown: TypeError: Cannot read properties of undefined (reading 'apply'),TypeError: Cannot read properties of undefined (reading 'apply')
at obj.<computed> (
http://localhost/DentalCadWeb/DependencyCGAL/testLib/emscripten/dllAndCommonLib/main.js:1:55081)
at wasm://wasm/34626aba:wasm-function[2]:0x9b
at wasm://wasm/004c86ce:wasm-function[154]:0x6bb81
at wasm://wasm/004c86ce:wasm-function[155]:0x6bba5
at Module._main (
http://localhost/DentalCadWeb/DependencyCGAL/testLib/emscripten/dllAndCommonLib/main.js:1:650962)
at callMain (
http://localhost/DentalCadWeb/DependencyCGAL/testLib/emscripten/dllAndCommonLib/main.js:1:2902021)
at doRun (
http://localhost/DentalCadWeb/DependencyCGAL/testLib/emscripten/dllAndCommonLib/main.js:1:2902599)
at
http://localhost/DentalCadWeb/DependencyCGAL/testLib/emscripten/dllAndCommonLib/main.js:1:2902754printErr @ main.html:1
main.js:1 Uncaught TypeError: Cannot read properties of undefined (reading 'apply')
at obj.<computed> (main.js:1:55081)
at 34626aba:0x9b
at 004c86ce:0x6bb81
at 004c86ce:0x6bba5
at Module._main (main.js:1:650962)
at callMain (main.js:1:2902021)
at doRun (main.js:1:2902599)
at main.js:1:2902754
This is my complete example with command line for main, dynamic library and static library
****************************** main ************************************
file: main.cpp
#include <dlfcn.h>
#include <stdio.h>
#include <emscripten.h>
int main()
{
printf("inizio programma\n");
int found = EM_ASM_INT(
return Module['preloadedWasm']['/library.so'] !== undefined;
);
if (!found) {
return 1;
}
void *lib_handle = dlopen("/library.so", 0);
if (!lib_handle) {
return 2;
}
typedef int (*sumfunc)(int,int);
sumfunc s = (sumfunc)dlsym(lib_handle, "sum");
printf("la somma di 3 e 4 è %d\n", s(3,4));
return 0;
}
#command line compilation
em++ main.cpp -o main.html -s MAIN_MODULE=1 --preload-file .@/ -O2 --use-preload-plugins -s EXPORT_ALL=1
****************** dynamic library *********************
file: library.c
#include <stdio.h>
#include "Common/CommonLib.h"
int sum(int x, int y) {
return x + diff(y,x);
}
#command line compilation
emcc library.c -s SIDE_MODULE=1 -O2 -o library.wasm -s EXPORT_ALL=1 -L/Common/build/libcommonLib.a
mv library.wasm library.so
****************** static library *********************
file: commonLib.h
int diff(int a, int b);
file: commonLib.cpp
#include <stdio.h>
#include "commonLib.h"
int diff(int a, int b)
{
printf("call diff with parameters a %d b %d\n",a,b);
return a-b;
}
#command line compilation
em++ -c commonLib.cpp
emar -r libcommonLib.a commonLib.o