[swift-users] 答复: hi every one ,who can help me? 3Q ~

Suipengfei suipengfei at huawei.com
Fri Jan 29 03:08:32 CST 2016


Hi ankit,

Really thank you very very much. I  can’t solve these problem for a lot of time.
You document is very clear and easy to understand.

Thank you again~

发件人: Ankit Agarwal [mailto:ankit.spd at gmail.com]
发送时间: 2016年1月29日 15:32
收件人: Suipengfei
抄送: swift-users at swift.org
主题: Re: [swift-users] hi every one ,who can help me? 3Q ~

You'll need to create a module map to import C modules. In practise it'll be easier to use swiftpm for such things. I had written a tutorial for this :

http://ankit.im/swift/2015/12/27/ship-c-code-with-swift-packages-using-swift-package-manager/

On Friday 29 January 2016, Suipengfei via swift-users <swift-users at swift.org<mailto:swift-users at swift.org>> wrote:

Hi all, I want to make a simple emample to show swift can call c library.



So ,I make a simple example,like this:



$ cat a.c

int add(int a,int b){

        return a + b;

}



And I make a lib,

$  gcc -o a.o -c a.c

$  ar rcs libmylib.a a.o



And I put libmylib.a in the same director with the main.swift



$ cat main.swift

import mylib

var b = add(10,20)

print(b)



when I compile :

$ swiftc  main.swift

main.swift:1:8: error: no such module 'mylib'

import mylib

       ^





I am just confused with this. Can you explain that with you pressure time. And what should I do?  Thank you a lot ~





--
Ankit

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160129/2799e433/attachment.html>


More information about the swift-users mailing list