tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone
https://tensorflow.org
Apache License 2.0
186.33k stars 74.31k forks source link

Compile selected tflite from bazel failed. #53557

Closed SefaZeng closed 2 years ago

SefaZeng commented 2 years ago

Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template

System information

Describe the current behavior I followed the example here https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/guide/reduce_binary_size.md to build a tflite library with selected tf ops. The BUILD file is:

load(  
    "@org_tensorflow//tensorflow/lite/delegates/flex:build_def.bzl",
    "tflite_flex_shared_library"
)         

# Shared lib target for convenience, pulls in the standard set of TensorFlow
# ops and kernels. The output library name is platform dependent:
#   - Linux/Android: `libtensorflowlite_flex.so`
#   - Mac: `libtensorflowlite_flex.dylib`
#   - Windows: `libtensorflowlite_flex.dll`
tflite_flex_shared_library(
  name = "tensorflowlite_flex",
  models = [ 
      ":opennmt.tflite",                                                                                                                                      
  ],   
)

Here is the build command:

bazel build -c opt --cxxopt='--std=c++14' \
      --config=monolithic \
      --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
      //tmp2:tensorflowlite_flex

And here is the full log:

INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=158
INFO: Reading rc options for 'build' from /data/nmt3/tensorflow_src/.bazelrc:
  Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /data/nmt3/tensorflow_src/.bazelrc:
  'build' options: --define framework_shared_object=true --java_toolchain=@tf_toolchains//toolchains/java:tf_java_toolchain --host_java_toolchain=@tf_toolchains//toolchains/java:tf_java_toolchain --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --enable_platform_specific_config --define=with_xla_support=true --config=short_logs --config=v2 --define=no_aws_support=true --define=no_hdfs_support=true --experimental_cc_shared_library --deleted_packages=tensorflow/compiler/mlir/tfrt,tensorflow/compiler/mlir/tfrt/benchmarks,tensorflow/compiler/mlir/tfrt/jit/python_binding,tensorflow/compiler/mlir/tfrt/jit/transforms,tensorflow/compiler/mlir/tfrt/python_tests,tensorflow/compiler/mlir/tfrt/tests,tensorflow/compiler/mlir/tfrt/tests/analysis,tensorflow/compiler/mlir/tfrt/tests/jit,tensorflow/compiler/mlir/tfrt/tests/lhlo_to_tfrt,tensorflow/compiler/mlir/tfrt/tests/tf_to_corert,tensorflow/compiler/mlir/tfrt/tests/tf_to_tfrt_data,tensorflow/compiler/mlir/tfrt/tests/saved_model,tensorflow/compiler/mlir/tfrt/transforms/lhlo_gpu_to_tfrt_gpu,tensorflow/core/runtime_fallback,tensorflow/core/runtime_fallback/conversion,tensorflow/core/runtime_fallback/kernel,tensorflow/core/runtime_fallback/opdefs,tensorflow/core/runtime_fallback/runtime,tensorflow/core/runtime_fallback/util,tensorflow/core/tfrt/common,tensorflow/core/tfrt/eager,tensorflow/core/tfrt/eager/backends/cpu,tensorflow/core/tfrt/eager/backends/gpu,tensorflow/core/tfrt/eager/core_runtime,tensorflow/core/tfrt/eager/cpp_tests/core_runtime,tensorflow/core/tfrt/fallback,tensorflow/core/tfrt/gpu,tensorflow/core/tfrt/run_handler_thread_pool,tensorflow/core/tfrt/runtime,tensorflow/core/tfrt/saved_model,tensorflow/core/tfrt/graph_executor,tensorflow/core/tfrt/saved_model/tests,tensorflow/core/tfrt/tpu,tensorflow/core/tfrt/utils
INFO: Found applicable config definition build:short_logs in file /data/nmt3/tensorflow_src/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /data/nmt3/tensorflow_src/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:monolithic in file /data/nmt3/tensorflow_src/.bazelrc: --define framework_shared_object=false
INFO: Found applicable config definition build:linux in file /data/nmt3/tensorflow_src/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels --distinct_host_configuration=false --experimental_guard_against_concurrent_changes
INFO: Found applicable config definition build:dynamic_kernels in file /data/nmt3/tensorflow_src/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/c3e082762b7664bbc7ffd2c39e86464928e27c0c.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_swift/releases/download/0.21.0/rules_swift.0.21.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_apple/releases/download/0.31.3/rules_apple.0.31.3.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/apple_support/releases/download/0.10.0/apple_support.0.10.0.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
INFO: Build option --define has changed, discarding analysis cache.
DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1596824487 -0400"
DEBUG: Repository io_bazel_rules_docker instantiated at:
  /data/nmt3/tensorflow_src/WORKSPACE:23:14: in <toplevel>
  /data/nmt3/tensorflow_src/tensorflow/workspace0.bzl:108:34: in workspace
  /root/.cache/bazel/_bazel_root/dadf5c5bfc89a01814f2e47e8a82306e/external/bazel_toolchains/repositories/repositories.bzl:35:23: in repositories
Repository rule git_repository defined at:
  /root/.cache/bazel/_bazel_root/dadf5c5bfc89a01814f2e47e8a82306e/external/bazel_tools/tools/build_defs/repo/git.bzl:199:33: in <toplevel>
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/XNNPACK/archive/113092317754c7dea47bfb3cb49c4f59c3c1fa10.zip failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/oneapi-src/oneDNN/archive/v2.5-rc.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
INFO: Analyzed target //tmp2:tensorflowlite_flex (1 packages loaded, 18165 targets configured).
INFO: Found 1 target...
ERROR: /data/nmt3/tensorflow_src/tensorflow/core/kernels/sparse/BUILD:32:18: Compiling tensorflow/core/kernels/sparse/mat_mul_op.cc failed: (Exit 1): gcc failed: error executing command /usr/local/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 215 argument(s) skipped)
tensorflow/core/kernels/sparse/mat_mul_op.cc: In lambda function:
tensorflow/core/kernels/sparse/mat_mul_op.cc:308:33: internal compiler error: in gimplify_var_or_parm_decl, at gimplify.c:1801
           HandleBatchAndRowRange(
                                 ^
0x92054c gimplify_var_or_parm_decl
        ../../gcc/gimplify.c:1801
0x9243b3 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:8485
0x921953 gimplify_modify_expr
        ../../gcc/gimplify.c:4644
0x92310b gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:8054
0x9258f6 gimplify_stmt(tree_node**, gimple_statement_base**)
        ../../gcc/gimplify.c:5519
0x925aaa gimplify_and_add(tree_node*, gimple_statement_base**)
        ../../gcc/gimplify.c:423
0x925aaa gimplify_init_ctor_eval
        ../../gcc/gimplify.c:3662
0x920ea6 gimplify_init_constructor
        ../../gcc/gimplify.c:4017
0x92179e gimplify_modify_expr_rhs
        ../../gcc/gimplify.c:4274
0x92187b gimplify_modify_expr
        ../../gcc/gimplify.c:4603
0x92310b gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:8054
0x9258f6 gimplify_stmt(tree_node**, gimple_statement_base**)
        ../../gcc/gimplify.c:5519
0x9270a8 gimplify_and_add(tree_node*, gimple_statement_base**)
        ../../gcc/gimplify.c:423
0x9270a8 internal_get_tmp_var
        ../../gcc/gimplify.c:568
0x922f36 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:8978
0x9286a0 gimplify_call_expr
        ../../gcc/gimplify.c:2477
0x9243e7 gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:8025
0x92492a gimplify_target_expr
        ../../gcc/gimplify.c:5445
0x92492a gimplify_expr(tree_node**, gimple_statement_base**, gimple_statement_base**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:8421
0x923308 gimplify_addr_expr
        ../../gcc/gimplify.c:4979
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
Target //tmp2:tensorflowlite_flex failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2829.962s, Critical Path: 291.83s
INFO: 3978 processes: 100 internal, 3878 local.
FAILED: Build did NOT complete successfully

Describe the expected behavior

Contributing

Standalone code to reproduce the issue Provide a reproducible test case that is the bare minimum necessary to generate the problem. If possible, please share a link to Colab/Jupyter/any notebook.

Other info / logs Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

sushreebarsa commented 2 years ago

@SefaZeng Could you please check the tested build configurations where it is recommended to use Python version 3.7-3.9 for TF v2.7.0? Please let us know if it helps?Thank you!

SefaZeng commented 2 years ago

@SefaZeng Could you please check the tested build configurations where it is recommended to use Python version 3.7-3.9 for TF v2.7.0? Please let us know if it helps?Thank you!

Thank you for your reply. I just found updating the gcc version solved this problem.
BTW, is there a example for how to use the shared library to inference the tflite model in c++? I found the example for static library but not for shared library. Thx in advance!

SefaZeng commented 2 years ago

After update the gcc version, I can successfully build the libtensorflowlite.so with the changes mentioned in #52113 . I also want to build the select ops for my model. I change the tensorflow/lite/BUILD with dependency like this:

tflite_cc_shared_object(
    name = "tensorflowlite",
    # Until we have more granular symbol export for the C++ API on Windows,
    # export all symbols.
    features = ["windows_export_all_symbols"],
    linkopts = select({
        "//tensorflow:macos": [
            "-Wl,-exported_symbols_list,$(location //tensorflow/lite:tflite_exported_symbols.lds)",
        ],
        "//tensorflow:windows": [],
        "//conditions:default": [
            "-Wl,-z,defs",
            "-Wl,--version-script,$(location //tensorflow/lite:tflite_version_script.lds)",
        ],
    }),  
    per_os_targets = True,
    deps = [
        ":framework",
        ":tflite_exported_symbols.lds",
        ":tflite_version_script.lds",
        #"//tensorflow/lite/kernels:builtin_ops_all_linked",
        "//tensorflow/lite/kernels:builtin_ops",
        "//tensorflow/lite/delegates/flex:delegate"                                                                                               
    ],   
)

And the build command is: bazel build -c opt --cxxopt=--std=c++14 --config=monolithic //tensorflow/lite:libtensorflowlite.so But when I try to use this shared library libtensorflowlite.so, it raise errors like this:

[ 50%] Building CXX object CMakeFiles/nmt.dir/nmt.cpp.o
[100%] Linking CXX executable nmt
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `VTT for std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::thread::_State::~_State()@GLIBCXX_3.4.22'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `__cxa_init_primary_exception@CXXABI_1.3.11'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::logic_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::range_error::range_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::length_error::length_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_of(char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::out_of_range::out_of_range(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::resize(unsigned long, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::overflow_error::overflow_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_not_of(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::default_error_condition(int) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy_chars(char*, char const*, char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::equivalent(std::error_code const&, int) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::invalid_argument::invalid_argument(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::resize(unsigned long, wchar_t)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::push_back(char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::equivalent(int, std::error_condition const&) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_not_of(char, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `typeinfo for std::thread::_State@GLIBCXX_3.4.22'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::~error_category()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())@GLIBCXX_3.4.22'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::logic_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(std::runtime_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::overflow_error::overflow_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(unsigned long, unsigned long, char const*) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::range_error::range_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(std::runtime_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::domain_error::domain_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::length_error::length_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace_aux(unsigned long, unsigned long, unsigned long, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `typeinfo for std::_V2::error_category@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_sync(char*, unsigned long, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `operator delete[](void*, unsigned long)@CXXABI_1.3.9'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::domain_error::domain_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_of(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_istringstream()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `VTT for std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()@GLIBCXX_3.4.26'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__atomic_futex_unsigned_base::_M_futex_wait_until(unsigned int*, unsigned int, bool, std::chrono::duration<long, std::ratio<1l, 1l> >, std::chrono::duration<long, std::ratio<1l, 1000000000l> >)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::underflow_error::underflow_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `operator delete(void*, unsigned long)@CXXABI_1.3.9'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::system_category()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::_M_message[abi:cxx11](int) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(unsigned long, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::underflow_error::underflow_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::invalid_argument::invalid_argument(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `typeinfo for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__exception_ptr::exception_ptr::exception_ptr(void*)@CXXABI_1.3.11'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::generic_category()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned long) const@GLIBCXX_3.4.21'
collect2: error: ld returned 1 exit status
make[2]: *** [nmt] Error 1
make[1]: *** [CMakeFiles/nmt.dir/all] Error 2
make: *** [all] Error 2

And the CMakeLists.txt is:

cmake_minimum_required(VERSION 3.16)
project(nmt C CXX)

ADD_LIBRARY(tensorflowlite SHARED IMPORTED)
set_property(TARGET tensorflowlite PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib/libtensorflowlite.so)

INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/tensorflow/lite")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/tensorflow")
INCLUDE_DIRECTORIES("/data/nmt3/temp/external")

INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-bin")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-out")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-tensorflow_src_2")
INCLUDE_DIRECTORIES("/data/nmt3/flatbuffers/include")
INCLUDE_DIRECTORIES("/data/nmt3/temp")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite")

link_directories("/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite")                                                                         
SET(CMAKE_CXX_FLAGS "-std=c++11 -O3")
add_executable(nmt nmt.cpp)
target_link_libraries(nmt libtensorflowlite.so)

I can't find anything useful about this error. Any helps?

SefaZeng commented 2 years ago

After update the gcc version, I can successfully build the libtensorflowlite.so with the changes mentioned in #52113 . I also want to build the select ops for my model. I change the tensorflow/lite/BUILD with dependency like this:

tflite_cc_shared_object(
    name = "tensorflowlite",
    # Until we have more granular symbol export for the C++ API on Windows,
    # export all symbols.
    features = ["windows_export_all_symbols"],
    linkopts = select({
        "//tensorflow:macos": [
            "-Wl,-exported_symbols_list,$(location //tensorflow/lite:tflite_exported_symbols.lds)",
        ],
        "//tensorflow:windows": [],
        "//conditions:default": [
            "-Wl,-z,defs",
            "-Wl,--version-script,$(location //tensorflow/lite:tflite_version_script.lds)",
        ],
    }),  
    per_os_targets = True,
    deps = [
        ":framework",
        ":tflite_exported_symbols.lds",
        ":tflite_version_script.lds",
        #"//tensorflow/lite/kernels:builtin_ops_all_linked",
        "//tensorflow/lite/kernels:builtin_ops",
        "//tensorflow/lite/delegates/flex:delegate"                                                                                               
    ],   
)

And the build command is: bazel build -c opt --cxxopt=--std=c++14 --config=monolithic //tensorflow/lite:libtensorflowlite.so But when I try to use this shared library libtensorflowlite.so, it raise errors like this:

[ 50%] Building CXX object CMakeFiles/nmt.dir/nmt.cpp.o
[100%] Linking CXX executable nmt
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `VTT for std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::thread::_State::~_State()@GLIBCXX_3.4.22'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `__cxa_init_primary_exception@CXXABI_1.3.11'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::logic_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::reserve(unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_of(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::range_error::range_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::length_error::length_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_of(char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::out_of_range::out_of_range(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::resize(unsigned long, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_erase(unsigned long, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::overflow_error::overflow_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_not_of(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::default_error_condition(int) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_copy_chars(char*, char const*, char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::equivalent(std::error_code const&, int) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::invalid_argument::invalid_argument(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::resize(unsigned long, wchar_t)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::out_of_range::out_of_range(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::push_back(char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::equivalent(int, std::error_condition const&) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_last_not_of(char, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `typeinfo for std::thread::_State@GLIBCXX_3.4.22'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct(unsigned long, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::~error_category()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)())@GLIBCXX_3.4.22'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::logic_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(std::runtime_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::overflow_error::overflow_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long&, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(unsigned long, unsigned long, char const*) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::range_error::range_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(std::runtime_error const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::domain_error::domain_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::length_error::length_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace_aux(unsigned long, unsigned long, unsigned long, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::getline<char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, char)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `typeinfo for std::_V2::error_category@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::_M_sync(char*, unsigned long, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `operator delete[](void*, unsigned long)@CXXABI_1.3.9'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `vtable for std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::domain_error::domain_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_of(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `VTT for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_istringstream()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::random_device::_M_init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `VTT for std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()@GLIBCXX_3.4.26'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::logic_error::logic_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__atomic_futex_unsigned_base::_M_futex_wait_until(unsigned int*, unsigned int, bool, std::chrono::duration<long, std::ratio<1l, 1l> >, std::chrono::duration<long, std::ratio<1l, 1000000000l> >)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::underflow_error::underflow_error(char const*)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char const*, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `operator delete(void*, unsigned long)@CXXABI_1.3.9'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::system_category()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace(unsigned long, unsigned long, char const*, unsigned long)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::error_category::_M_message[abi:cxx11](int) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(unsigned long, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::underflow_error::underflow_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::invalid_argument::invalid_argument(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find(char const*, unsigned long, unsigned long) const@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `typeinfo for std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::runtime_error::runtime_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__exception_ptr::exception_ptr::exception_ptr(void*)@CXXABI_1.3.11'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::_V2::generic_category()@GLIBCXX_3.4.21'
/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite/libtensorflowlite.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(char, unsigned long) const@GLIBCXX_3.4.21'
collect2: error: ld returned 1 exit status
make[2]: *** [nmt] Error 1
make[1]: *** [CMakeFiles/nmt.dir/all] Error 2
make: *** [all] Error 2

And the CMakeLists.txt is:

cmake_minimum_required(VERSION 3.16)
project(nmt C CXX)

ADD_LIBRARY(tensorflowlite SHARED IMPORTED)
set_property(TARGET tensorflowlite PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/lib/libtensorflowlite.so)

INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/tensorflow/lite")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/tensorflow")
INCLUDE_DIRECTORIES("/data/nmt3/temp/external")

INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-bin")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-out")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-tensorflow_src_2")
INCLUDE_DIRECTORIES("/data/nmt3/flatbuffers/include")
INCLUDE_DIRECTORIES("/data/nmt3/temp")
INCLUDE_DIRECTORIES("/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite")

link_directories("/data/nmt3/tensorflow_src_2/bazel-bin/tensorflow/lite")                                                                         
SET(CMAKE_CXX_FLAGS "-std=c++11 -O3")
add_executable(nmt nmt.cpp)
target_link_libraries(nmt libtensorflowlite.so)

I can't find anything useful about this error. Any helps?

This is mainly caused by the confusion of my local GCC environment, which has multiple versions of GCC. Now I can run the demo codes, but all the returned result is 0. Still debugging.

google-ml-butler[bot] commented 2 years ago

Are you satisfied with the resolution of your issue? Yes No