Swift Objective-C interoperability on Linux, error: 'Foundation/Foundation.h' file not found

↘锁芯ラ 提交于 2019-12-11 14:09:43

问题


I'm trying to compile a swift program that uses code written in Objective-C on a VM running Linux (Ubuntu 16.0.4, Swift 4.0.3).

I get this error when compiling :

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

On Mac OS

The same program works perfectly on Mac OS.

What have I tried ?

I've tried reverting to swift 3.1.1 (I remember this working on swift 3 a while ago).

I've googled the problem, extensively, and had no success.

I've followed instructions on how to install the Objective-C runtime on Linux and installed GNUStep (see http://www.techotopia.com/index.php/Installing_and_Using_GNUstep_and_Objective-C_on_Linux)

All with no success.

why am I using objective-C ?

(Anticipating this question).

I need to call a python script from the program. Python has a library for C, which I can only use with C or Objective-C.

In fact, commenting out the line #import <Foundation/Foundation.h> makes compilation fail when importing the Python library :

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

回答1:


Swift on Linux is not interoperable with Objective-C, it is interoperable with C.

According to https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#c-language-targets, you can have plain C code as part of your package, in a separate target.

You can also link your package with a C library, see https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#c-language-targets.

In your case I would use the later approach and would link your code with the Python C library.



来源:https://stackoverflow.com/questions/47997335/swift-objective-c-interoperability-on-linux-error-foundation-foundation-h-fi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!