2017-12-27 1754 views
0

我想编译一个swift程序,它使用在运行Linux(Ubuntu 16.0.4)的虚拟机上用Objective-C编写的代码,Swift 4.0.3)。Linux上的Swift Objective-C互操作性错误:找不到'Foundation/Foundation.h'文件

我编译时出现此错误:

fatal error: 'Foundation/Foundation.h' file not found 
#import <Foundation/Foundation.h> 
     ^
1 error generated. 

在Mac OS

相同的程序完美的作品在Mac OS。

我试过了什么?

我试过恢复到迅速3.1.1(我记得这个工作在快速3前一阵子)。

我已经广泛地搜索了这个问题,但没有成功。

我已经按照有关如何安装Linux上的Objective-C运行指令和安装GNUstep的(见http://www.techotopia.com/index.php/Installing_and_Using_GNUstep_and_Objective-C_on_Linux

所有没有成功。

为什么我使用objective-C?

(预测此问题)。

我需要从程序中调用python脚本。 Python有一个C库,我只能用C或Objective-C。

事实上,注释掉行#import <Foundation/Foundation.h>导入Python库时发出编译失败:在Linux上

fatal error: 'Python/Python.h' file not found 
#include <Python/Python.h> 
     ^
1 error generated. 
+0

看起来您的基金会和Python框架的副本不在系统标题路径中。 –

+0

@JoshCaswell,谢谢。我怎样才能验证这一点? – kmn

回答

2

斯威夫特是Objective-C的不能互操作,它与C.

据互操作到 https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#c-language-targets,您可以将纯C代码作为您的软件包的一部分,放在单独的目标中。

您还可以将您的软件包与C库链接,请参阅https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#c-language-targets

在你的情况下,我会使用后面的方法,并将您的代码与Python C库链接。