简体   繁体   English

在XCode / iOS中实现C代码

[英]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. 我觉得这是一个白痴,但我试图在我的项目中实现一些C代码,但我一直有无法解释的问题。

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. 根据我过去的经验,我可以创建.h和.c文件,实现.c中的函数并在.h中声明它们。 Then I could import the .h into another file to have visible access to the functions. 然后我可以将.h导入到另一个文件中,以便可以访问这些函数。

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. 我已将.c包含在编译源列表中并将其添加为目标,但我被告知它无法找到这些函数。 Okay. 好的。 Then I tried using a .h and .m pair, but now I am getting a SIGABRT in my main() without any error description. 然后我尝试使用.h和.m对,但现在我在main()中得到一个SIGABRT而没有任何错误描述。

Here is an example (not sample) of my .m code: 这是我的.m代码的示例(不是示例):

static NSArray *_myArray

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

I've already #imported all necessary framework classes, as well. 我已经#imported所有必要的框架类。

So, at the end of it all, I just want to know the steps for creating the necessary files and implementing my C code. 所以,最后,我只想知道创建必要文件和实现我的C代码的步骤。 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. 我希望得到答案,而不是解决方法,因为我确信可以将C文件包含到XCode项目中。

Xcode is happy to let you use C sources in your project; Xcode很高兴让您在项目中使用C源代码; 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. 从那里,展开“编译源”部分,并确保列出您的C源。

If it is, you'll need to examine the full compiler output to understand what is happening. 如果是,则需要检查完整的编译器输出以了解发生的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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