emscripten-core / emscripten-core/emscripten

Cannot get Boost regex to work

Open
#11,754 4 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Hi everyone,

I'm completely stuck with the following issue. I am trying to compile the worlds' most simple Boost regex program to WASM using Emscripten. I created [a repository](https://github.com/donalffons/boost-regex-emscripten-test/blob/master/boosttest1/main.cpp), which hopefully makes it more clear to explain what I am doing in detail.
This is the code that I want to compile. I'm using cmake.
```C++
#include

#include
#include

int main() {
std::string s = "Boost Libraries";
boost::regex expr{"(\\w+)\\s(\\w+)"};
boost::smatch what;
if (boost::regex_search(s, what, expr))
{
std::cout << what[0] << '\n';
std::cout << what[1] << "_" << what[2] << '\n';
}
return 0;
}
```
# Attempt 1: Using `-s USE_BOOST_HEADERS=1` (boosttest1)

I just added this for _completeness_. I assume this is not working, because I need more than the header files to get this to work. Nonetheless, here is my CMakeLists.txt:
```CMake
project(boosttest)
add_executable(boosttest main.cpp)
SET(CMAKE_EXECUTABLE_SUFFIX ".html")
set_target_properties(boosttest PROPERTIES COMPILE_FLAGS "-s USE_BOOST_HEADERS=1" LINK_FLAGS "-s USE_BOOST_HEADERS=1")
```
And here is the output during the build
```
# ...
Scanning dependencies of target boosttest
[ 50%] Building CXX object CMakeFiles/boosttest.dir/main.o
[100%] Linking CXX executable boosttest.html
error: undefined symbol: _ZN5boost11regex_errorC1ERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS_15regex_constants10error_typeEl (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN5boost11regex_errorC1ERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS_15regex_constants10error_typeEl may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost11regex_errorD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN5boost11regex_errorD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700011raw_storage6insertEmm (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700011raw_storage6insertEmm may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700011raw_storage6resizeEm (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700011raw_storage6resizeEm may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700013get_mem_blockEv (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700013get_mem_blockEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700013put_mem_blockEPv (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700013put_mem_blockEPv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700014verify_optionsEjNS_15regex_constants12_match_flagsE (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700014verify_optionsEjNS_15regex_constants12_match_flagsE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700019raise_runtime_errorERKSt13runtime_error (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700019raise_runtime_errorERKSt13runtime_error may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700024get_default_error_stringENS_15regex_constants10error_typeE (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700024get_default_error_stringENS_15regex_constants10error_typeE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700027cpp_regex_traits_char_layerIcE4initEv (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700027cpp_regex_traits_char_layerIcE4initEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700027lookup_default_collate_nameERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700027lookup_default_collate_nameERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost24scoped_static_mutex_lockC1ERNS_12static_mutexEb (referenced by top-level compiled C/C++ code)
warning: __ZN5boost24scoped_static_mutex_lockC1ERNS_12static_mutexEb may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost24scoped_static_mutex_lockD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN5boost24scoped_static_mutex_lockD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZNK5boost11regex_error5raiseEv (referenced by top-level compiled C/C++ code)
warning: __ZNK5boost11regex_error5raiseEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/home/sebastian/boosttest/emsdk/node/12.18.1_64bit/bin/node /home/sebastian/boosttest/emsdk/upstream/emscripten/src/compiler.js /tmp/tmp60y26u4o.txt' failed (1)
make[2]: *** [CMakeFiles/boosttest.dir/build.make:105: boosttest.html] Error 1
make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/boosttest.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
```

# Attempt 2: Building my own Boost with Emscripten (boosttest2)
I download a recent version of boost and configure and build it. I then create an .a file from all the .bc files in the binary folder.
```
mkdir -p buildBoost
cd buildBoost
wget https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.gz
tar -xf boost_1_73_0.tar.gz
cd boost_1_73_0
./bootstrap.sh --without-icu
emconfigure ./b2 toolset=emscripten --disable-icu threading=single variant=release regex

cd bin.v2/libs/regex/build/emscripten-1.39.20/release/visibility-hidden
emar q libboost_regex.a cpp_regex_traits.bc cregex.bc c_regex_traits.bc fileiter.bc icu.bc instances.bc posix_api.bc regex.bc regex_debug.bc regex_raw_buffer.bc regex_traits_defaults.bc static_mutex.bc usinstances.bc w32_regex_traits.bc wc_regex_traits.bc wide_posix_api.bc winstances.bc
```

And here is the build output:
```
configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/sebastian/boosttest/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/home/sebastian/boosttest/emsdk/node/12.18.1_64bit/bin/node"
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sebastian/boosttest/boosttest2/build
Scanning dependencies of target boosttest
[ 50%] Building CXX object CMakeFiles/boosttest.dir/main.cpp.o
[100%] Linking CXX executable boosttest.html
error: undefined symbol: _ZN5boost16re_detail_10700011raw_storage6insertEmm (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN5boost16re_detail_10700011raw_storage6insertEmm may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700011raw_storage6resizeEm (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700011raw_storage6resizeEm may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700013get_mem_blockEv (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700013get_mem_blockEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700013put_mem_blockEPv (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700013put_mem_blockEPv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700014verify_optionsEjNS_15regex_constants12_match_flagsE (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700014verify_optionsEjNS_15regex_constants12_match_flagsE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700019raise_runtime_errorERKSt13runtime_error (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700019raise_runtime_errorERKSt13runtime_error may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700024get_default_error_stringENS_15regex_constants10error_typeE (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700024get_default_error_stringENS_15regex_constants10error_typeE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700027cpp_regex_traits_char_layerIcE4initEv (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700027cpp_regex_traits_char_layerIcE4initEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN5boost16re_detail_10700027lookup_default_collate_nameERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE (referenced by top-level compiled C/C++ code)
warning: __ZN5boost16re_detail_10700027lookup_default_collate_nameERKNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/home/sebastian/boosttest/emsdk/node/12.18.1_64bit/bin/node /home/sebastian/boosttest/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpwxegruas.txt' failed (1)
make[2]: *** [CMakeFiles/boosttest.dir/build.make:107: boosttest.html] Error 1
make[1]: *** [CMakeFiles/Makefile2:96: CMakeFiles/boosttest.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
```

So... That doesn't work either. I would greatly appreciate it if there is anyone out there who can help me with this. Thanks a lot!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.