swift-cgo-example
swift-cgo-example copied to clipboard
Unable to access the library(minimal.a) on another machine
With the help of this project I was able to create the library(minimal.a). I utilised this library for accessing swift code through go. I am accessing swift code through my go executable using this library. It is all working fine on my machine. However, I get following error when I try to execute it on other machines. dyld: Symbol not found: _$sBOWV Referenced from: minimal.a Expected in: /usr/lib/libswiftCore.dylib in minimal.a Abort trap: 6
I thought this is some kind of linking issue so I statically linked the library using following command "xcrun swiftc minimalC.o minimalS.o -static-stdlib -emit-library -module-name minimal -o minimal.a". Using -static-stdlib the issue got resolved.
But, -static-stdlib is not supported on latest MacOS. So my question is how can I use this library on other machines without using -static-stdlib.
Note: Utilised this method to access swift from go but, underlying code is different
Thanks for reporting this issue. To be frank, I have not worked with swift for quite some time. Do you mind telling me what versions of XCode, Swift, and MacOS your two machines are using?
Development machine is having this configuration XCODE 8.2.1, MacOS 10.12, and swift 3.0.2. I was deploying this library on other machines MacOS 10.11, 10.14 there is no xcode installed on these machines. I was able to overcome this issue by following steps.
- Use otool to find the dependancies of the library generated. Execute command "- otool -L minimal.a" for the same.
- The above step will reveal all the dependant libraries used. In my case there were some libraries with rpath such as "@rpath/libswiftAppKit.dylib".
- minimal.a was unable to locate these libraries with rpath on the other machines. I provided all these dependant libraries from my machine along with this minimal.a. The libraries were copied in one folder named libs. After this I had to update the linker path for these dependant libraries in minimal.a so that it was able to refer them on any machine.
- I had to add rpath for these dependant libraries. This was done by command "install_name_tool -add_rpath @loader_path/libs minimal.a".
Details about the runtime linking on mac can be found at below link. It is very well explained... https://matthew-brett.github.io/docosx/mac_runtime_link.html