Compiling Assembly (.S) file alongside iPhone project-Collection of common programming errors

In my iPhone project, I have an assembly file named arm_asm_stub.S, which contains a method I need to call from another file in my project called main.c. When I don’t #include the file at the top of my main.c file, I get no build errors, but I do get the linker error:

Undefined symbols for architecture armv7:
  "_execute_arm_translate", referenced from:
      _iphone_main in main.o

However, when I attempt to #include the file at the top of main.c, Xcode uses Clang to compile arm_asm_stub.S and so I get a bunch of errors, ones that don’t appear when I don’t #include the file such as:

unknown type name 'ldr'
expected identifier or '('
use of undeclared identifier 'sp'

How can Xcode compile this one file separately than the rest of the project?

  1. You should just add the .S file to your project and the build system will automatically assemble it. Be careful with the symbols though. All C functions have an underscore prepended to them by the compiler, so your assembly language routine label needs an underscore at the front for C code to be able to call it.

Originally posted 2013-11-10 00:09:51.