Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[boost-filesystem] Error linking with boost-filesystem whilst using Emscripten #39346

Closed
uniformization opened this issue Jun 17, 2024 · 4 comments
Assignees
Labels
category:question This issue is a question

Comments

@uniformization
Copy link

uniformization commented Jun 17, 2024

Describe the bug
When compiling my application, the linking process fails because boost-filesystem was not compiled with -pthread on Emscripten. The error is as follows:

wasm-ld: error: --shared-memory is disallowed by exception.cpp.o because it was not compiled with 'atomics' or 'bulk-memory' features.

Environment

  • OS: Windows
  • Compiler: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61 (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)

To Reproduce
Steps to reproduce the behavior:

  1. Clone the demo I made for this issue: git clone https://github.com/uniformization/boost-error-vcpkg-test.git.
  2. Run the preset then build it: cmake --preset vcpkg-emscripten && cmake --build --preset emscripten.
  3. See error.

Expected behavior
The program should link successfully.

Failure logs
build.log

Additional context
I created a quick demo so any reviewer can see the setup I'm using: https://github.com/uniformization/boost-error-vcpkg-test/.

@Neumann-A
Copy link
Contributor

Not really an issue with vcpkg but your assumption about the emscripten triplet.
vcpkg just includes include("${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake") you however want to also have

string(APPEND CMAKE_CXX_FLAGS " -sWASM=1 -sUSE_PTHREADS -pthread")
string(APPEND CMAKE_C_FLAGS " -sWASM=1 -sUSE_PTHREADS -pthread")

So write your own emscripten triplet/toolchain and add the required flags? (Or adjust CFLAGS and CXXFLAGS in your environment accordingly.)

@Cheney-W Cheney-W added the category:question This issue is a question label Jun 18, 2024
@dg0yt
Copy link
Contributor

dg0yt commented Jun 18, 2024

string(APPEND CMAKE_CXX_FLAGS " -sWASM=1 -sUSE_PTHREADS -pthread")
string(APPEND CMAKE_C_FLAGS " -sWASM=1 -sUSE_PTHREADS -pthread")

AFAIU -pthread is all what is needed today:
https://emscripten.org/docs/porting/pthreads.html#pthreads-support

Why should this be handled in the triplet/toolchain for emscripten? This is normally detected/added by the packages, for other platforms.

Or adjust CFLAGS and CXXFLAGS in your environment accordingly.

Doesn't this have an effect on building host dependencies?

@Neumann-A
Copy link
Contributor

Why should this be handled in the triplet/toolchain for emscripten? This is normally detected/added by the packages, for other platforms.

If you read https://emscripten.org/docs/porting/pthreads.html#pthreads-support carefully:

Pass the compiler flag -pthread when compiling any .c/.cpp files, AND when linking to generate the final output .js file.

which basically means it is an all or nothing flag which also is inline with my experience with it while testing microsoft/vcpkg-tool#1315 with wasm. You will just get errors that abc wasn't build with thread support.

Doesn't this have an effect on building host dependencies?

Hmm yes. So setting CFLAGS and CXXFLAGS in the triplet is required, e.g.:

set(ENV{CXXFLAGS} " -sWASM=1 -sUSE_PTHREADS -pthread")
set(ENV{CFLAGS}  " -sWASM=1 -sUSE_PTHREADS -pthread")

@uniformization
Copy link
Author

So write your own emscripten triplet/toolchain and add the required flags? (Or adjust CFLAGS and CXXFLAGS in your environment accordingly.)

This worked perfectly, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:question This issue is a question
Projects
None yet
Development

No branches or pull requests

4 participants