从Xcode调用C库函数

时间:2018-12-19 12:58:36

标签: swift xcode bridging-header

桥接头文件说,

#define qnorm5        Rf_qnorm5
#define qnorm qnorm5

double  qnorm5(double, double, double, int, int);

和代码(编译!)说

let myresult = qnorm (0.75,0,1,1,0)

但是链接器抱怨

Undefined symbols for architecture x86_64:
  "_qnorm", referenced from:
      macOS_app_test.ViewController.sayButtonClicked(Any) -> () in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

从输出中,找到并链接了正确的库,但是链接器没有查找正确的符号。链接器应查找的符号为_Rf_qnorm5

1 个答案:

答案 0 :(得分:0)

显然,我应该知道正确的函数名称应为Rf_qnorm5

此外,XCode实际查找桥接头文件时存在问题。两者都安装到位,代码即可工作。