ffmpeg-on-apple-silicon icon indicating copy to clipboard operation
ffmpeg-on-apple-silicon copied to clipboard

Script Failing on: ld: symbol(s) not found for architecture arm64

Open joeyboey opened this issue 4 years ago • 11 comments

I alway get the error ld: symbol(s) not found for architecture arm64 when trying to execute the build script. Any advice?

joeyboey avatar Dec 12 '20 16:12 joeyboey

Can you post the log around that part?

ssut avatar Dec 12 '20 17:12 ssut

Of course!

ld: warning: ignoring file /usr/local/Cellar/libpng/1.6.37/lib/libpng16.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "_png_create_info_struct", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_create_read_struct", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_destroy_read_struct", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_error", referenced from:
      _read_data_from_FT_Stream in libfreetype.a(sfnt.o)
  "_png_get_IHDR", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_get_error_ptr", referenced from:
      _error_callback in libfreetype.a(sfnt.o)
      _read_data_from_FT_Stream in libfreetype.a(sfnt.o)
  "_png_get_io_ptr", referenced from:
      _read_data_from_FT_Stream in libfreetype.a(sfnt.o)
  "_png_get_valid", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_read_end", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_read_image", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_read_info", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_read_update_info", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_expand_gray_1_2_4_to_8", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_filler", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_gray_to_rgb", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_interlace_handling", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_longjmp_fn", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
      _error_callback in libfreetype.a(sfnt.o)
  "_png_set_packing", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_palette_to_rgb", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_read_fn", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_read_user_transform_fn", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_strip_16", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
  "_png_set_tRNS_to_alpha", referenced from:
      _Load_SBit_Png in libfreetype.a(sfnt.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [fc-cache] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

joeyboey avatar Dec 12 '20 21:12 joeyboey

Can you try installing libtool with the arm64 version of Homebrew? (located in /opt/homebrew)

ssut avatar Dec 13 '20 09:12 ssut

It was already installed:

Warning: libtool 2.4.6_2 is already installed and up-to-date
To reinstall 2.4.6_2, run `brew reinstall libtool`

It still fails after a reinstall.

joeyboey avatar Dec 13 '20 10:12 joeyboey

So I cleared the workdir. Now it failes even sooner because nasmis not downloaded at all. All I can find is yasm.

+ echo '♻️ ' Start compiling NASM
♻️  Start compiling NASM
+ cd /Users/joe/workdir/compile
+ cd nasm-2.15.05
./build.bash: line 167: cd: nasm-2.15.05: No such file or directory

It seems to download nasm but under the name yasm:

+ echo 'Downloading: nasm (2.15.05)'
Downloading: nasm (2.15.05)
+ curl -Ls -o - http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
+ tar zxf - -C /Users/joe/workdir/compile/
+ tar zxf - -C /Users/joe/workdir/compile/
+ tar zxf - -C /Users/joe/workdir/compile/

For comparison this is how homebrew is installed:

joe@MacBook-Pro ~ % which brew
/opt/homebrew/bin/brew
joe@MacBook-Pro ~ % brew --prefix
/opt/homebrew
joe@MacBook-Pro ~ % which ibrew
ibrew: aliased to arch -x86_64 /usr/local/bin/brew
joe@MacBook-Pro ~ % ibrew --prefix
/usr/local

After another clearing of the workdir, nasm works fine, the first error comes up again.

When I just try to execute ld this is the output:

joe@MacBook-Pro ~ % ld -v
@(#)PROGRAM:ld  PROJECT:ld64-609.7
BUILD 18:10:15 Oct 19 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 12.0.0, (clang-1200.0.32.27) (static support for 27, runtime is 27)
TAPI support using: Apple TAPI version 12.0.0 (tapi-1200.0.23.4)

But this is the apple version, not the one from homebrew, right?

joeyboey avatar Dec 13 '20 11:12 joeyboey

The nasm error is related to the download domain being temporarily unavailable.

Could you maybe provide your compiled version as a release, then we could just use this until the build process is a little bit more reliable.

Edit: There is a prebuilt package available: ffmpeg 4.3.1 arm64

joeyboey avatar Dec 13 '20 23:12 joeyboey

Same error happened to me

ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)```

Prushka avatar Jan 08 '21 05:01 Prushka

how do we create arm64e/x86_64 universal library? looks like it only generate the lib same as system CPU arch

stang2019 avatar Jan 08 '21 21:01 stang2019

I updated the 'arm64' to 'arm64 x86_64' to check if I could get the universal

if [[ "$(uname -m)" == "arm64" ]]; then export ARCH=arm64 x86_64 else export ARCH=x86_64 fi

stang2019 avatar Jan 08 '21 21:01 stang2019

still only arm64

lipo -info ./libavcodec.a Non-fat file: ./libavcodec.a is architecture: arm64

stang2019 avatar Jan 08 '21 23:01 stang2019

ffmpeg depend other libs(libpng16, freetype .. ), you also need to link them to your target.

what's more, wrap ffmpeg header file with extern C while including them in c++ code. like:

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavutil/mathematics.h"
}

nicklezheng avatar Jun 04 '22 09:06 nicklezheng