tpoechtrager / cctools-port

Apple cctools port for Linux and *BSD
731 stars 168 forks source link

ld: symbol(s) not found for architecture x86_64 #157

Closed zijiren233 closed 2 months ago

zijiren233 commented 2 months ago

An error occurred when I built using the iPhoneSimulator SDK. This is how I compiled it:

sed -i 's|iPhoneOS|iPhoneSimulator|g' usage_examples/ios_toolchain/build.sh
sed -i 's|^TRIPLE=.*|TRIPLE="x86_64-apple-darwin11"|' usage_examples/ios_toolchain/build.sh
bash usage_examples/ios_toolchain/build.sh "$SDK_FILE" x86_64

The error appeared, how should I fix it?

   /usr/bin/mkdir -p '/usr/local/ioscross/share/man/man5'
   /usr/bin/install -c -m 644 '../../../../../cctools/man/Mach-O.5' '/usr/local/ioscross/share/man/man5/x86_64-apple-darwin11-Mach-O.5'
   /usr/bin/install -c -m 644 '../../../../../cctools/man/a.out.5' '/usr/local/ioscross/share/man/man5/x86_64-apple-darwin11-a.out.5'
   /usr/bin/install -c -m 644 '../../../../../cctools/man/ranlib.5' '/usr/local/ioscross/share/man/man5/x86_64-apple-darwin11-ranlib.5'
   /usr/bin/install -c -m 644 '../../../../../cctools/man/stab.5' '/usr/local/ioscross/share/man/man5/x86_64-apple-darwin11-stab.5'
  make[2]: Leaving directory '/cctools-port/usage_examples/ios_toolchain/tmp/cctools/man'
  make[1]: Leaving directory '/cctools-port/usage_examples/ios_toolchain/tmp/cctools/man'
  make[1]: Entering directory '/cctools-port/usage_examples/ios_toolchain/tmp/cctools'
  make[2]: Entering directory '/cctools-port/usage_examples/ios_toolchain/tmp/cctools'
  make[2]: Nothing to be done for 'install-exec-am'.
  make[2]: Nothing to be done for 'install-data-am'.
  make[2]: Leaving directory '/cctools-port/usage_examples/ios_toolchain/tmp/cctools'
  make[1]: Leaving directory '/cctools-port/usage_examples/ios_toolchain/tmp/cctools'
  *** checking toolchain ***
  Undefined symbols for architecture x86_64:
    "start", referenced from:
       implicit entry/start for main executable
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
tpoechtrager commented 2 months ago

Make sure the target CPU/arch is correctly set.

https://github.com/tpoechtrager/cctools-port/blob/1010.6-ld64-951.9/usage_examples/ios_toolchain/wrapper.c#L1C1-L3C7

Add -v here in build.sh to see what's wrong:

echo "int main(){return 0;}" | $TRIPLE-clang -v -xc -O2 -o test - 1>/dev/null || exit 1

zijiren233 commented 2 months ago

It should be due to me setting export IPHONEOS_DEPLOYMENT_TARGET=5.0, which caused the compilation to succeed when I removed this environment variable.

zijiren233 commented 2 months ago

I see that the TARGET_CPU parameter is only used by the wrapper, and its purpose is to add a default -arch parameter value in the wrapper. Does this mean I can compile once and use the wrapper toolchain to build for other architectures, for example, using arm-apple-darwin11-clang -arch x86_64, without having to recompile bash usage_examples/ios_toolchain/build.sh $SDK_FILE x86_64? Or do I need to change TRIPLE to x86_64-apple-darwin11 to use -arch x86_64?

Un1q32 commented 2 months ago

IDK why the wrapper.c file is used when a simple shell script would work better. The target should be x86_64-apple-darwin11. The wrapper.c should pass -miphoneos-version-min=4.2 automatically which will make clang target the iphone simulator. Then you just need an iphone simulator sdk (the normal iOS and macOS SDKs will not work)