proxy-wasm / proxy-wasm-cpp-sdk

WebAssembly for Proxies (C++ SDK)
Apache License 2.0
140 stars 68 forks source link

Build wasm(libprotobuf.a failed with undefined symbol(std::__2::__basic_string_common<true>::__throw_length_error() const) #145

Open coolg92003 opened 2 years ago

coolg92003 commented 2 years ago

I Use make file Makefile.base to build below 4 files failed with below errors, any suggestions? 4 files: HFEDHttpScreen.h HFEDHttpScreen.cc Below two files are build by (protoc --proto_path=${SRC_DIR} --cpp_out=${DST_DIR} ${SRC_DIR}/HFEDHttpScreenMsg.proto) /usr/local/bin/protoc --version libprotoc 3.9.1 HFEDHttpScreenMsg.pb.h HFEDHttpScreenMsg.pb.cc

When trigger to build wasm file with below command em++ --no-entry -s EXPORTED_FUNCTIONS=['_malloc'] -sLLD_REPORT_UNDEFINED -Wl,--trace-symbol=ZNKSt3220vector_base_commonILb1EE20throw_length_errorEv -std=c++17 -O3 -flto -Ic++-noexcept -I${PROXY_WASM_CPP_SDK} -I${PB_DIR} -I/usr/local/include --js-library ${PROXY_WASM_CPP_SDK}/proxy_wasm_intrinsics.js $.cc ${PROXY_WASM_CPP_SDK}/proxy_wasm_intrinsics.pb.cc ${PB_DIR}/HFEDHttpScreenMsg.pb.cc ${CPP_CONTEXT_LIB} ${PROXY_WASM_CPP_SDK}/libprotobuf.a -o $.wasm

Below error occured in libprotobuf.a(this file is from this proxy-wasm-ccp-sdk repo em++ --no-entry -s EXPORTED_FUNCTIONS=['_malloc'] -sLLD_REPORT_UNDEFINED -Wl,--trace-symbol=ZNKSt3220vector_base_commonILb1EE20throw_length_errorEv -std=c++17 -O3 -flto -Ic++-noexcept -I/root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk -I/root/cfx/cfx_httpScreen/protobuf/cfx/pbJsonIn -I/usr/local/include --js-library /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/proxy_wasm_intrinsics.js HFEDHttpScreen.cc /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/proxy_wasm_intrinsics.pb.cc /root/cfx/cfx_httpScreen/protobuf/cfx/pbJsonIn/HFEDHttpScreenMsg.pb.cc /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/proxy_wasm_intrinsics.cc /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a -o HFEDHttpScreen.wasm wasm-ld: warning: Linking two modules of different data layouts: '/root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o at 588630)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'

wasm-ld: warning: Linking two modules of different data layouts: '/root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(int128.o at 655570)' is 'e-m:e-p:32:32-i64:64-n32:64-S128' whereas 'ld-temp.o' is 'e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20'

_wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::__2::char_traits, std::2::allocator>::basic_string(std::2::basic_string<char, std::__2::char_traits, std::2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::__2::char_traits, std::2::allocator>::basic_string(std::2::basic_string<char, std::__2::char_traits, std::2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::__2::char_traits, std::2::allocator>::basic_string(std::2::basic_string<char, std::__2::char_traits, std::2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::__throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::vector_base_common::__throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::2::char_traits, std::__2::allocator>::basic_string(std::2::basic_string<char, std::2::char_traits, std::__2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::2::char_traits, std::__2::allocator>::basic_string(std::2::basic_string<char, std::2::char_traits, std::__2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::2::char_traits, std::__2::allocator>::basic_string(std::2::basic_string<char, std::2::char_traits, std::__2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::vector_base_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::vector_base_common::__throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string<char, std::2::char_traits, std::__2::allocator>::basic_string(std::2::basic_string<char, std::2::char_traits, std::__2::allocator> const&) wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::vector_base_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::__throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::throw_length_error() const wasm-ld: error: /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a(common.o): undefined symbol: std::2::basic_string_common::__throw_lengtherror() const wasm-ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) em++: error: '/root/cfx/cfx_httpScreen/emsdk/upstream/bin/wasm-ld -o HFEDHttpScreen.wasm --trace-symbol=ZNKSt3220vector_base_commonILb1EE20throw_length_errorEv /tmp/emscripten_temp_5k8_itu8/HFEDHttpScreen_0.o /tmp/emscripten_temp_5k8_itu8/proxy_wasm_intrinsics.pb_1.o /tmp/emscripten_temp_5k8_itu8/HFEDHttpScreenMsg.pb_2.o /tmp/emscripten_temp_5k8_itu8/proxy_wasm_intrinsics_3.o /root/cfx/cfx_httpScreen/proxy-wasm-cpp-sdk/libprotobuf.a -L/root/cfx/cfx_httpScreen/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto /root/cfx/cfx_httpScreen/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/lto/crt1_reactor.o -lGL -lal -lhtml5 -lstandalonewasm -lstubs -lnoexit -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/tmp16b0u6w5.undefined --strip-debug --export-if-defined=malloc --export-if-defined=start_em_asm --export-if-defined=stop_em_asm --export-if-defined=start_em_js --export-if-defined=stop_em_js --export=stackSave --export=stackRestore --export=stackAlloc --export=__errno_location --export=malloc --export=__cxa_is_pointer_type --export-table -z stack-size=5242880 --initial-memory=16777216 --entry=_initialize --max-memory=16777216 --global-base=1024' failed (returned 1) make: *** [Makefile.base_hs:14: HFEDHttpScreen.wasm] Error 1

coolg92003 commented 2 years ago

em++ version is 3.1.23 Also run command "em++ --clear-cache" and no any improvement

coolg92003 commented 2 years ago

do this make file again, then works now cat Makefile_pb CPP_API ?= .

all: proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h HFEDHttpScreenMsg.pb.h ${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a

protobuf: proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h HFEDHttpScreenMsg.pb.h

proxy_wasm_intrinsics.pb.h: proxy_wasm_intrinsics.proto protoc --cpp_out=. proxy_wasm_intrinsics.proto

proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h: proxy_wasm_intrinsics_lite.proto protoc --cpp_out=. -I. proxy_wasm_intrinsics_lite.proto protoc --cpp_out=. struct_lite.proto

HFEDHttpScreenMsg.pb.h: HFEDHttpScreenMsg.proto protoc --proto_path=. --cpp_out=. HFEDHttpScreenMsg.proto

${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a: rm -rf protobuf-wasm && git clone https://github.com/protocolbuffers/protobuf protobuf-wasm \ && cd protobuf-wasm && git checkout v3.9.1 \ && rm -rf wasm-patches && git clone https://github.com/kwonoj/protobuf-wasm wasm-patches \ && cd wasm-patches && git checkout 4bba8b2f38b5004f87489642b6ca4525ae72fe7f \ && cd .. && git apply wasm-patches/*.patch \ && ./autogen.sh \ && emconfigure ./configure --disable-shared CXXFLAGS="-O3 -flto" \ && emmake make \ && cd .. \ && cp protobuf-wasm/src/.libs/libprotobuf-lite.a ${CPP_API}/libprotobuf-lite.a \ && cp protobuf-wasm/src/.libs/libprotobuf.a ${CPP_API}/libprotobuf.a

clean: rm -f proxy_wasm_intrinsics.pb.h proxy_wasm_intrinsics_lite.pb.h struct_lite.pb.h HFEDHttpScreenMsg.pb.h ${CPP_API}/libprotobuf.a ${CPP_API}/libprotobuf-lite.a

thanks