-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
The question is: How to use system library source code files provided by emscripten, for example: https://github.com/emscripten-core/emscripten/blob/main/system/lib/libc/musl/src/linux/epoll.c ?
When I compile a c/c++ project (i.e. an example code at https://github.com/uNetworking/uSockets) to WASM, erros occured as following:
......
[ 85%] Built target uSockets
[ 92%] Building C object CMakeFiles/httpServer.dir/http_server.c.o
[100%] Linking C executable httpServer.js
error: undefined symbol: epoll_create1 (referenced by top-level compiled C/C++ code)
warning: Link with -sLLD_REPORT_UNDEFINED to get more information on undefined symbols
warning: To disable errors for undefined symbols use -sERROR_ON_UNDEFINED_SYMBOLS=0
warning: _epoll_create1 may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: epoll_ctl (referenced by top-level compiled C/C++ code)
warning: _epoll_ctl may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: epoll_wait (referenced by top-level compiled C/C++ code)
warning: _epoll_wait may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: eventfd (referenced by top-level compiled C/C++ code)
warning: _eventfd may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: timerfd_create (referenced by top-level compiled C/C++ code)
warning: _timerfd_create may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: timerfd_settime (referenced by top-level compiled C/C++ code)
warning: _timerfd_settime may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
emcc: error: '/home/dev_tools/emsdk/node/14.18.2_64bit/bin/node /home/dev_tools/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpqx7zx6d7.json' failed (returned 1)
make[2]: *** [CMakeFiles/httpServer.dir/build.make:101: httpServer.js] Error 1
make[1]: *** [CMakeFiles/Makefile2:111: CMakeFiles/httpServer.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
emmake: error: 'make' failed (returned 2)
I searched the undefined symbols, such as epoll_create1, epoll_wait, epoll_ctl, etc., and found that they are in the file epoll.h, which is located at : /home/dev_tools/emsdk/upstream/emscripten/cache/sysroot/include/sys/epoll.h,
whose functions are defined in: /home/dev_tools/emsdk/upstream/emscripten/system/lib/libc/musl/src/linux/epoll.c. This code file belongs to a system library libc provided by emscripten.
Even I add these function names into EXPORTED_FUNCTIONS by target_link_options(httpServer PRIVATE -sLINKABLE=1) in CMakeLists, the erros are the same.
The guidance "How do I link against system libraries ..." (https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-link-against-system-libraries-like-sdl-boost-etc) says : System libraries that are included with Emscripten are automatically linked when you compile (just the necessary parts). This includes libc, libc++ (C++ standard library) and SDL.
So, why do the errors occur with undefined symbols,. e.g. epoll_create1, epoll_wait, epoll_ctl, etc. ?
Do I need to explicitly and manually add all source code files provided by emscripten ( e.g. in the libc library) when I build a c/c++ program/library into WASM ?
How can I fix this issue ?
I appreciate an early reply and comments. Thanks.