Linking in prebuilt libraries #50
Replies: 1 comment 1 reply
-
Hi @formatc2013, Thanks so much for your feedback and the kind words about Cpp.js. Cpp.js first compiles packages into static libraries, then passes these packages as parameters to emcc to convert them to WebAssembly. When resolving packages to be passed to emcc, I've implemented two steps:
I had never tried adding another package with target_link_libraries before. When compiled this way, I believe I can detect where the library is created and provide it to emcc. This should solve your problem. Additionally, integration with package managers like Conan hadn't occurred to me before - this expands my vision. I'll be working on this integration this week. Independent of these solutions, I tried an experiment. I first compiled the project https://github.com/bugra9/cpp.js/tree/main/packages/cppjs-sample-lib-prebuilt-matrix with cpp.js.
I replaced the static library generated by cpp.js with the one created by Conan2. Thanks again for all the great input! |
Beta Was this translation helpful? Give feedback.
-
Hi @bugra9 !
Thanks for this awesome tool.
I am struggling to link in libraries to the Cloudflare sample project,(proof of concept at our company to leverage a large C++20 code base) built outside of the cppjs build environment, with emscipten.
I tried a few things, but in a few words I used the sample cmake sample, and I tried to call:
target_link_libraries(cppjs_internal_lib XYZ path/to/some/other/lib)
Basically link together the sample cmake lib with a library build with emscripten, fails to work, with undefined symbol linker errors.
I tried to use the same libraries, only with pure emscripten, and I could successfully link it together and use/load it in the node terminal.
If I build the dependency lib with add_subdirectory(), inside the cppjs build system it works okay.
If add sources (generated by emscripten/conan ) to a target as object files or llvm bitcode it also works.
Only linking fails.
I checked and if not mistaken cppjs uses clang18, and I verified my binaries are also build by clang18.
(checked by: strings yourbinary.a | grep clang).
Verified symbols with emnm xyz.a | grep somefunction; symbols present with T.
What are the specific compiler/linker flags, that I must use in order to be able to link into cppjs build libraries?
Does it have to happen in the cppjs docker image?
Would you be able to provide a minimal example how to build a linkable external library?
Or an example with conan?
I also tried to integrate parts of our build system into cppjs, but has a lots of dependencies and uses other tools than cmake, so consuming prebuilt libs/headers would be preferred.
Much appreciated
PS: Can prepare a repro if needed
Beta Was this translation helpful? Give feedback.
All reactions