Question

Basically I am able to create and compile a static library in xcode4 but the functions are not being read in by otool. I managed to do it once so that it would work but every other time since then it has failed so I know I must be missing an obvious step.

What I currently do is create a new view based application in xcode4, I then add a new target (Numbers), to Numbers I add a source file called File.c and its content is:

static int Get10()
{
    return 10;
}

Then I compile it (making sure I've selected Numbers |iPhone 4.3 Simulator in the build scheme drop down).

But when I run otool -S on libNumbers.a I get no results:

size of ranlib structures: 0 (number 0) object offset string index

I know there should be some stuff there because if I run otool -S on the correctly built libNumbers.a I get some numbers instead of 0s:

size of ranlib structures: 16 (number 2) object offset string index 136 0 136 7

I really don't know what I'm doing wrong exactly, I've tried backtracing what I did with the succesful lib compile I made but haven't really found anything to indicate why the functions compiled with that one but not these.

Was it helpful?

Solution

Don't use static if you want to use the function outside of the translation unit it is defined in. You want external linkage for the function instead by just leaving out the static part (external linkage is the default for functions).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top