M1 Mac下clang++链接fftw3库出现arm64架构未定义符号问题
M1 Mac(Monterey系统)下C++项目链接FFTW3库出现arm64架构符号未定义错误
环境
- M1芯片Mac,系统版本为Monterey
- FFTW3库与clang 14均通过Macports安装
测试代码
#include <fftw3.h> int main() { fftwf_complex *fc = fftwf_alloc_complex(1); return 0; }
编译命令
sudo /opt/local/bin/clang++-mp-14 -v -I/opt/local/include/ -L/opt/local/lib/ -lfftw3 -o /Users/ajw/test/test_exec /Users/ajw/test/main.cpp
链接错误信息
Undefined symbols for architecture arm64: "_fftwf_alloc_complex", referenced from: _main in main-cfb5fd.o
完整编译输出
clang version 14.0.6 Target: arm64-apple-darwin21.6.0 Thread model: posix InstalledDir: /opt/local/libexec/llvm-14/bin "/opt/local/libexec/llvm-14/bin/clang" -cc1 -triple arm64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -ffp-contract=on -fno-rounding-math -funwind-tables=2 -target-sdk-version=13.1 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=lldb -target-linker-version 711 -v -fcoverage-compilation-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -resource-dir /opt/local/libexec/llvm-14/lib/clang/14.0.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I /opt/local/include/ -I/usr/local/include -stdlib=libc++ -internal-isystem /opt/local/libexec/llvm-14/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/local/libexec/llvm-14/lib/clang/14.0.6/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -fdeprecated-macro -fdebug-compilation-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/main-cfb5fd.o -x c++ /Users/ajw/test/main.cpp clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target arm64-apple-darwin21.6.0 ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include" ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks" #include "..." search starts here: #include <...> search starts here: /opt/local/include /opt/local/libexec/llvm-14/bin/../include/c++/v1 /opt/local/libexec/llvm-14/lib/clang/14.0.6/include /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory) End of search list. "/opt/local/libexec/llvm-14/bin/ld" -demangle -lto_library /opt/local/libexec/llvm-14/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 12.0.0 13.1 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o /Users/ajw/test/test_exec -L/opt/local/lib/ -L/usr/local/lib -lfftw3 /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/main-cfb5fd.o -lc++ -lSystem /opt/local/libexec/llvm-14/lib/clang/14.0.6/lib/darwin/libclang_rt.osx.a Undefined symbols for architecture arm64: "_fftwf_alloc_complex", referenced from: _main in main-cfb5fd.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
已尝试操作与疑问
- 已将库和头文件移至系统默认路径,且确认路径已出现在链接器参数中,但问题仍未解决
- 清楚该错误通常意味着未找到对应库,但不确定具体原因,怀疑问题出在fftw3.h中的名字修饰宏,它会为
alloc_complex这类函数名添加fftw3f_前缀
内容的提问来源于Stack Exchange,提问作者jwaj1
相关产品推荐
相关产品推荐

