2
votes

Can anybody provide a simple example of how to compile and link a function in a standalone ARM assembly file (a .s file) that compiles in XCode 4.5 for iPhone with the llvm 4.1 compiler ? In other words, latest XCode with default compiler.

I'm trying to call the ARM assembly function from a .cc or .mm file (both cplusplus compatible).

I would like to drop this file into one of the XCode template projects for iPhone (such as OpenGL Game) and call the function defined within (say a function that adds 1 to the input int and returns the value).

I tried this example: Compile Arm Assembly directly in XCode

I get a linker failure when I try the code from this posting: Undefined symbols for architecture armv7: "add_in_asm(int)", referenced from:

Thanks much.

1

1 Answers

2
votes

Since you are using C++/ObjC++, the linker won't find a C name unless it is declared as such. Thus, you should declare your function as

extern "C" int myfunction(...); // or what signature ever...