从目标C调用C [英] Calling C from Objective C

查看:63
本文介绍了从目标C调用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉目标c& C.我正在尝试在目标C程序中使用此随机生成器c库 .我的理解是,目标c是c的严格超集,因此这应该是可能的.

I'm new to objective c & c. I'm trying to use this random generator c library in an objective c program. My understanding is that objective c is a strict superset of c so this should be possible.

我的代码可以编译并运行,但是会收到很多警告.

My code compiles and runs but I get a lot of warnings.

  • 警告:函数"mt_seed32"的隐式声明
  • 警告:函数"mt_lrand"的隐式声明
  • 警告:语义问题:函数"mt_seed32"的隐式声明在C99中无效
  • 警告:语义问题:函数'mt_lrand'的隐式声明在C99中无效
  • 警告:语义问题:使用类型为int的表达式初始化uint32_t *(aka unsigned int *)的指针到指针转换的整数不兼容
  • warning: implicit declaration of function 'mt_seed32'
  • warning: implicit declaration of function 'mt_lrand'
  • warning: Semantic Issue: Implicit declaration of function 'mt_seed32' is invalid in C99
  • warning: Semantic Issue: Implicit declaration of function 'mt_lrand' is invalid in C99
  • warning: Semantic Issue: Incompatible integer to pointer conversion initializing uint32_t * (aka unsigned int *) with an expression of type int

我还没有将C头文件导入到目标c类中-它只是找到了它.如果导入,则会出现重复的方法错误.

I have not imported the C header file to the objective c class - it just finds it. If I import it I get duplicate method errors.

C库头文件:

extern void     mt_seed32(uint32_t seed);

extern uint32_t     mt_lrand(void); 

调用它的代码:[我尝试用[self method()]调用它,但是崩溃

Code to call it: [I've tried calling it with [self method()] but that crashes

mt_seed32(3);

uint32_t *i = mt_lrand();

谁能告诉我如何摆脱这些警告?

Can anyone tell me how too get rid of these warnings?

推荐答案

最后一个编译器错误发生是因为mt_lrand();返回一个int,而不是指向int的指针.因此,最后一行应该是

The last compiler error happens because mt_lrand(); returns an int, not a pointer to an int. Therefore, the last line should be

uint32_t i = mt_lrand();

所有其他错误是由于您没有#include库头而导致的.您能否发布包含库标头时发生的错误?

All the other errors are due to the fact that you did not #include the library header. Could you please post the errors that occur when you do include the library header?

这篇关于从目标C调用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆