Custom module with external library

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By qofa

I am trying to create a very simple module. The module simply calls a function from a library. The library is also very simple. It is a C++ class with one function that just prints out to std::cout. I have been having a very hard time getting godot to build with it.

I am building the library from source myself. I make the .a library file and “include” header files available for godot.

If I build the library using g++ and set the godot platform target to x11, I am able to compile godot with a module that uses the library. Building godot for any other platform fails.

client_interface is my library.

platform=javascript

scons: Reading SConscript files ...
['register_types.cpp', 'summator.cpp']
WebM SIMD optimizations are disabled. Check if your CPU architecture, CPU bits or platform are supported!
Checking for C header file mntent.h... (cached) yes
scons: done reading SConscript files.
scons: Building targets ...
[ 41%] Compiling ==> modules/summator/summator.cpp
[100%] progress_finish(["progress_finish"], [])
[100%] Linking Static Library ==> modules/libmodules.javascript.debug.bc
Ranlib Library         ==> modules/libmodules.javascript.debug.bc
[100%] Linking Program        ==> bin/godot.javascript.debug.js
wasm-ld: error: unknown file type: client_interface.cpp.o
shared:ERROR: '/mnt/c/Users/user/dev/game/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_EKsCDY/godot.javascript.debug.wasm --lto-O0 platform/javascript/audio_driver_javascript.javascript.debug.bc platform/javascript/http_client_javascript.javascript.debug.bc -L/mnt/c/Users/user/dev/game/emsdk/upstream/emscripten/system/local/lib platform/javascript/javascript_eval.javascript.debug.bc -L/mnt/c/Users/user/dev/game/emsdk/upstream/emscripten/system/lib platform/javascript/javascript_main.javascript.debug.bc -L/home/user/.emscripten_cache/wasm-obj platform/javascript/os_javascript.javascript.debug.bc -L/mnt/c/Users/user/dev/game/server_simple_lib/build/lib main/libmain.javascript.debug.bc modules/libmodules.javascript.debug.bc platform/libplatform.javascript.debug.bc drivers/libdrivers.javascript.debug.bc scene/libscene.javascript.debug.bc servers/libservers.javascript.debug.bc core/libcore.javascript.debug.bc modules/freetype/libfreetype_builtin.javascript.debug.bc /mnt/c/Users/user/dev/game/server_simple_lib/build/lib/libclientlib.a /home/user/.emscripten_cache/wasm-obj/libc.a /home/user/.emscripten_cache/wasm-obj/libcompiler_rt.a /home/user/.emscripten_cache/wasm-obj/libc-wasm.a /home/user/.emscripten_cache/wasm-obj/libc++-noexcept.a /home/user/.emscripten_cache/wasm-obj/libc++abi-noexcept.a /home/user/.emscripten_cache/wasm-obj/libgl-webgl2-ofb.a /home/user/.emscripten_cache/wasm-obj/libdlmalloc-debug.a /home/user/.emscripten_cache/wasm-obj/libpthread_stub.a /home/user/.emscripten_cache/wasm-obj/libc_rt_wasm.a /home/user/.emscripten_cache/wasm-obj/libsockets.a --allow-undefined --import-memory --import-table -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --export __wasm_call_ctors --export __data_end --export main --export malloc --export free --export setThrew --export __errno_location --export fflush --export _ZSt18uncaught_exceptionv --export _get_environ --export emscripten_webgl_make_context_current --export emscripten_webgl_get_current_context --export htonl --export htons --export ntohs --export realloc --export emscripten_main_thread_process_queued_calls --export _get_tzname --export _get_daylight --export _get_timezone --export emscripten_GetProcAddress --export strstr -z stack-size=5242880 --initial-memory=16777216 --no-entry --global-base=1024' failed (1)
scons: *** [bin/godot.javascript.debug.js] Error 1
scons: building terminated because of errors.

platform=windows

scons: Reading SConscript files ...
Configuring for Windows: target=debug, bits=default
Using MinGW
['register_types.cpp', 'summator.cpp']
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
[ 57%] Compiling ==> modules/summator/summator.cpp
[100%] progress_finish(["progress_finish"], [])
[100%] Linking Static Library ==> modules/libmodules.windows.tools.64.a
[100%] Ranlib Library         ==> modules/libmodules.windows.tools.64.a
[100%] Linking Program        ==> bin/godot.windows.tools.64.exe
modules/libmodules.windows.tools.64.a(summator.windows.tools.64.o): In function `Summator::reset()':
/mnt/c/Users/user/dev/game/godot/modules/summator/summator.cpp:15: undefined reference to `client::ClientInterface::ClientInterface()'
/mnt/c/Users/user/dev/game/godot/modules/summator/summator.cpp:15: undefined reference to `client::ClientInterface::~ClientInterface()'
collect2: error: ld returned 1 exit status
scons: *** [bin/godot.windows.tools.64.exe] Error 1
scons: building terminated because of errors.

I thought it may be an issue with my library being built with a different compiler than what godot is using. I tried building my library with x86_64-w64-mingw32-g++ and compiling godot for windows but I encounter the same error. Am I out of ideas.

Have you found a solution to your problem? I have the exact same problem …

Nico | 2022-10-07 16:54