Undefined symbols for architecture arm64 linking to fftw-3 with clang-14

huangapple go评论75阅读模式
英文:

Undefined symbols for architecture arm64 linking to fftw-3 with clang-14

问题

我正在尝试在M1 Mac上的C++项目中使用fftw-3库(OS版本为Monterey)。fftw-3库和clang都是通过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

我理解这个错误通常意味着找不到库(类似问题请参考https://stackoverflow.com/questions/20299961/undefine-symbols-for-architecture-x86-64-using-fftw),但我对为什么出现这个错误感到困惑。

下面是完整的输出:

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)

我尝试将库和头文件移动到默认系统路径,但无论

英文:

I'm trying to use the fftw-3 library in a C++ project on an M1 Mac (OS version Monterey).
Both the fftw-3 lib and clang were installed via Macports.

Test code:

#include &lt;fftw3.h&gt;
int main() {
  fftwf_complex *fc = fftwf_alloc_complex(1);
  return 0;
}

Compiler call:

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 

Linker error:

Undefined symbols for architecture arm64:
  &quot;_fftwf_alloc_complex&quot;, referenced from:
      _main in main-cfb5fd.o

I understand that this error usually means the library isn't being found (there's a similar questions here: https://stackoverflow.com/questions/20299961/undefine-symbols-for-architecture-x86-64-using-fftw), but I'm stumped as to why.

Here's the whole output:

clang version 14.0.6
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-14/bin
 &quot;/opt/local/libexec/llvm-14/bin/clang&quot; -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 &quot;/usr/local/include&quot;
ignoring nonexistent directory &quot;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include&quot;
ignoring nonexistent directory &quot;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks&quot;
#include &quot;...&quot; search starts here:
#include &lt;...&gt; 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.
 &quot;/opt/local/libexec/llvm-14/bin/ld&quot; -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:
  &quot;_fftwf_alloc_complex&quot;, 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)

I tried moving lib and header into default system paths, but no matter what paths I used (that I verified show up in the linker args), I still get the problem.

I wonder if the problem is the name-mangling macro in fftw3.h that looks like it prepends "fftw3f_" to function names like "alloc_complex".

答案1

得分: 1

看起来你在单精度和双精度版本的库之间感到困惑(fftw3f与fftw3)。请注意,fftwf_alloc_complexfftw_alloc_complex 的单精度版本(其他带有 fftw_/fftwf_ 前缀的FFT函数类似)。

请将你的命令行链接选项从 -lfftw3 更改为 -lfftw3f,以链接单精度(float)库。有关更多详细信息,请参阅 FFTW 手册

英文:

It looks like you’re getting confused between the single and double precision versions of the library (fftw3f v fftw3). Note that fftwf_alloc_complex is the single precision version of fftw_alloc_complex (and similarly for other FFT functions with fftw_/fftwf_ prefixes).

Change your command line link options from -lfftw3 to -lfftw3f in order to link the single precision (float) library. See the FFTW manual for further details.

huangapple
  • 本文由 发表于 2023年1月6日 14:59:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75027885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定