Kotlin/Native lld-link: error: undefined symbol: std::__throw_bad_array_new_length()
2024-02-21 20:02:57

0. 问题

在 GitHub Workflow 或者 本地运行 Kotlin/Native 的 link 任务报错:
本地 & GitHub 环境:

1
2
os = Windows
compiler = GCC 11.2.0

以下为在 GitHub Workflow 上的日志片段

1
2
3
4
5
6
7
8
9
10
11
12
13
e: C:\Users\runneradmin\.konan\dependencies\llvm-11.1.0-windows-x64-essentials/bin/clang++ invocation reported errors

The C:\Users\runneradmin\.konan\dependencies\llvm-11.1.0-windows-x64-essentials/bin/clang++ command returned non-zero exit code: 1.
output:
lld-link: error: undefined symbol: std::__throw_bad_array_new_length()
>>> referenced by <Linked Lib name>.a(ThreadController.cpp.obj):(LibLoader::sendPluginException(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >))
>>> referenced by <Linked Lib name>.a(ThreadController.cpp.obj):(LibLoader::ThreadController::submitJob(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>))
>>> referenced by <Linked Lib name>.a(ThreadController.cpp.obj):(LibLoader::ThreadController::callThreadEnd(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void ()>))
>>> referenced 16 more times
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

> Task :<Proj name>:linkDebugExecutableNative FAILED
:<Proj name>:linkDebugExecutableNative (Thread[Execution worker for ':',5,main]) completed. Took 3 mins 10.585 secs.

1. 原因

造成的原因是 Kotlin/Native 是用 GCC 9.2.0 的(见 KT-51975), 但是我在 Kotlin/Native 里的 cintrop 里 link 了一个用 GCC 11.2.0 编译的静态库.

2. 解决方法

用 GCC 10 / 9 重新编译要 link 的静态库或者改用动态库

Prev
2024-02-21 20:02:57
Next