libiconv

starlitxiling Lv3

Macos下使用cargo编译项目时遇到libiconv库出现问题,错误信息如下:

1
2
3
4
5
ld: warning: object file (/Users/xiling/Work/dora/target/debug/libdora_node_api_cxx.a(78d20d63abadd48c-cxx.o)) was built for newer macOS version (15.1) than being linked (15.0)

dyld[47942]: Symbol not found: _libiconv
Referenced from: <29AEB045-6BB1-322B-8FB5-689632E9E693> /Users/xiling/Work/dora/target/debug/dora
Expected in: <510E7C30-C723-33EF-A25D-1760261B21E2> /usr/lib/libiconv.2.dylib

这个问题是使用的libiconv库与macos环境中的不匹配,我们需要使用brew安装一个,brew install libiconv
再找项目的根目录下创建.cargo文件夹,在此文件夹下创建config.toml文件,文件中写入:

1
2
3
4
[build]
rustflags = ["-L", "/opt/homebrew/Cellar/libiconv/1.18/lib"]

# rustflags = ["-C", "link-arg=-mmacosx-version-min=15.0", "-L", "/opt/homebrew/Cellar/libiconv/1.18/lib"] # 可能你也需要这个

然后就可以正常编译了。

你可以使用otool工具检查可执行文件是否正确链接到libiconv,命令是otool -L /Users/xiling/Work/dora/target/debug/dora, 检查输出中是否正确引用/opt/homebrew/Cellar/libiconv/1.18/lib/libiconv.2.dylib

使用nm确认符号_libiconv存在于libiconv中。nm /opt/homebrew/Cellar/libiconv/1.18/lib/libiconv.2.dylib | grep _libiconv

以上只可能存在的解决办法,并不能确保一定能解决类似的问题,如果不能,你可以查看_libiconv or _iconv undefined symbol on Mac OSX

  • Title: libiconv
  • Author: starlitxiling
  • Created at : 2025-01-02 14:22:48
  • Updated at : 2025-01-02 14:38:29
  • Link: http://starlitxiling.github.io/2025/01/02/libiconv/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
libiconv