I am trying to create a macOS application using Crystal and libui. I am able to compile a crystal executable with all of the required libraries statically, so it can run on any mac (partially static). For some reason, the shard I am using which is called "hedron" (the crystal bindings for libui), I am unable to compile the program using libui.a, like I am compiling my program with libevent.a and libgc.a. I am only able to build successfully with libui.A.dylib.
I have changed the top of bindings file of the shard to @[Link(ldflags: "#{__DIR__}/../../../../vendor/libui.A.dylib")]
, and I am compiling my program using shards build --release --link-flags="-L
pwd/vendor"
. In the vendor folder of my project, I have libevent.a, libssl.a, libgc.a, libcrypto.a, and libui.A.dylib. The project compiles ok. Then I run otool -L ./bin/CrystalDistroTest
and I get the following output:
./bin/CrystalDistroTest:
@rpath/libui.A.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libpcre.0.dylib (compatibility version 1.0.0, current version 1.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
Even when I copy libui.A.dylib into the ./bin directory, it does not start up on other computers. It starts on mine because I have libui.A.dylib in my /usr/local/lib directory. My end goal is to package this into a .app folder for only macOS distribution. Where should I put the libui.A.dylib so my executable can find it?
Figured it out by compiling with shards build --release --link-flags="-rpath @executable_path/../Frameworks -L
pwd/vendor"
. I just needed to add the -rpath @executable_path/../Frameworks
to the linker.