Create dynamic library

Hi .. I have created dynamic library in swift . After inspecting dynamic library by following command

nm -u filename.dylib

Name of the function in .dylib is different from the .swift file for example
In swift file it is like
In dynamic lib file

How can I make both function name same ?

Swift uses mangled names as they are a full representation of the resolved name of a symbol (which include module, namespaces, name, arguments, etc). You might want to read about its rules here.

I am neither an expert on this sort of thing, nor can I fathom what your use case is, but would @_cdecl be any help?

Yes, @_cdecl is the way to do this today. Be aware that, as with any underscored attribute, there is no guarantee that it will continue to be supported in the future (it may be renamed or removed, or its semantics may change in a future version of Swift; renaming is by far the most likely possibility), so any code using it is not source-stable.

Thank you @DeFrenZ @scanon :blush:

Terms of Service

Privacy Policy

Cookie Policy