简体   繁体   中英

Implement C code in XCode / iOS

I feel like an idiot with all of this, but I am trying to implement some C code that I have into my project, but I keep having unexplained issues.

From my past experience, I could create a .h and a .c file, implement the functions in the .c and declare them in the .h. Then I could import the .h into another file to have visible access to the functions.

I've included the .c in the compile sources list and added it as a target, but I am being told that it can't find the functions. Okay. Then I tried using a .h and .m pair, but now I am getting a SIGABRT in my main() without any error description.

Here is an example (not sample) of my .m code:

static NSArray *_myArray

NSArray *myArray(){return (_myArray) ? : (_myArray = [NSArray arrayWithObjects:@1, @2, @3, nil]);}

I've already #imported all necessary framework classes, as well.

So, at the end of it all, I just want to know the steps for creating the necessary files and implementing my C code. I'm hoping to get that answer, rather than a work around, as I'm sure that it's possible to include C files into an XCode project.

Xcode is happy to let you use C sources in your project; you only need to provide them in your project(of course) and also make sure they're specified for your target(not always intuitive).

Click your project name in the navigator so you can access the Build Rules for your project. From there, expand the "Compile Sources" section, and make certain your C source is listed.

If it is, you'll need to examine the full compiler output to understand what is happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM