<div dir="ltr">I simplified your example package and posted a bug report here: <a href="https://bugs.swift.org/browse/SR-3556">https://bugs.swift.org/browse/SR-3556</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 5, 2017 at 9:59 PM, Yang Yang via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>sorry, i made mistake on compiling. It still report the same link error.</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888">Yang</font></span><div><div class="h5"><br><div class="gmail_quote"><div>On Wed, Jan 4, 2017 at 11:20 PM Yang Yang <<a href="mailto:cometyang@gmail.com" target="_blank">cometyang@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_3645077133313571189gmail_msg"><div class="m_3645077133313571189gmail_msg">Thanks.</div>It compiled successfully now under linux.<div class="m_3645077133313571189gmail_msg"><br class="m_3645077133313571189gmail_msg"></div></div><div class="gmail_extra m_3645077133313571189gmail_msg"><br class="m_3645077133313571189gmail_msg"><div class="gmail_quote m_3645077133313571189gmail_msg">2017-01-04 12:29 GMT-06:00 Joe Groff <span class="m_3645077133313571189gmail_msg"><<a href="mailto:jgroff@apple.com" class="m_3645077133313571189gmail_msg" target="_blank">jgroff@apple.com</a>></span>:<br class="m_3645077133313571189gmail_msg"><blockquote class="gmail_quote m_3645077133313571189gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="m_3645077133313571189gmail_msg"><br class="m_3645077133313571189gmail_msg"><br><br>> On Dec 30, 2016, at 11:17 AM, Yang Yang via swift-users <<a href="mailto:swift-users@swift.org" class="m_3645077133313571189gmail_msg" target="_blank">swift-users@swift.org</a>> wrote:<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br></span><div class="m_3645077133313571189gmail_msg"><div class="m_3645077133313571189m_-5854707686072664887h5 m_3645077133313571189gmail_msg">> I try to wrap a c library in swift package named Test.<br class="m_3645077133313571189gmail_msg"><br><br>> The code looks like this:<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> Test1.h<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> struct MyParams {<br class="m_3645077133313571189gmail_msg"><br><br>> int (*func)();<br class="m_3645077133313571189gmail_msg"><br><br>> };<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> typedef struct MyParams MyParams;<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> Test2.h<br class="m_3645077133313571189gmail_msg"><br><br>> #include "Test1.h"<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> static int test(){<br class="m_3645077133313571189gmail_msg"><br><br>> return 0;<br class="m_3645077133313571189gmail_msg"><br><br>> }<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> void myTest()<br class="m_3645077133313571189gmail_msg"><br><br>> {<br class="m_3645077133313571189gmail_msg"><br><br>> MyParams params;<br class="m_3645077133313571189gmail_msg"><br><br>> params.func = test;<br class="m_3645077133313571189gmail_msg"><br><br>> }<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> Then I try to import the package into swift code and use<br class="m_3645077133313571189gmail_msg"><br><br>> in Test.swift.<br class="m_3645077133313571189gmail_msg"><br><br>> ************************<br class="m_3645077133313571189gmail_msg"><br><br>> import Test<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> class TestSwift {<br class="m_3645077133313571189gmail_msg"><br><br>> func runtest(){<br class="m_3645077133313571189gmail_msg"><br><br>> myTest()<br class="m_3645077133313571189gmail_msg"><br><br>> }<br class="m_3645077133313571189gmail_msg"><br><br>> }<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> However, the compiler report link error:<br class="m_3645077133313571189gmail_msg"><br><br>> function myTest: error: undefined reference to 'test'<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> If I comment out<br class="m_3645077133313571189gmail_msg"><br><br>> "params.func = test;" in myTest.<br class="m_3645077133313571189gmail_msg"><br><br>><br class="m_3645077133313571189gmail_msg"><br><br>> It successfully build. How should I handle this situation?<br class="m_3645077133313571189gmail_msg"><br><br><br class="m_3645077133313571189gmail_msg"><br><br></div></div>Try making `test` static inline instead of just static.<br class="m_3645077133313571189gmail_msg"><br><br><span class="m_3645077133313571189m_-5854707686072664887HOEnZb m_3645077133313571189gmail_msg"><font color="#888888" class="m_3645077133313571189gmail_msg"><br class="m_3645077133313571189gmail_msg"><br><br>-Joe<br class="m_3645077133313571189gmail_msg"><br><br><br class="m_3645077133313571189gmail_msg"><br><br></font></span></blockquote></div><br class="m_3645077133313571189gmail_msg"></div><br><br></blockquote></div></div></div></div>
<br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Ankit<br><br></div>
</div>