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="-Lpwd/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 -Lpwd/vendor". I just needed to add the -rpath #executable_path/../Frameworks to the linker.
Related
I built a simple app using Crystal on a Mac, and it appears to depend upon two libraries (.dylib).
What is the simplest way to distribute that app (would zipping the .dylib(s) along with the executable in a given directory work), or do I have to use a tool like install_name_tool to rewrite the path to the libraries?
In other words, if the required libraries are in the same directory than the executable, will the executable find them or is the path to libraries hard-coded in a Mac application?
otool -L ./bin/hello: yields:
./bin/hello:
/opt/homebrew/opt/bdw-gc/lib/libgc.1.dylib (compatibility version 7.0.0, current version 7.1.0)
/opt/homebrew/opt/libevent/lib/libevent-2.1.7.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
This is my first time creating an installer for an application and I need some advice.
This application depends on A.dylib, and A.dylib depends on two other libraries: libstdc++.6.dylib and libgomp.1.dylib which all come from the gcc folder. When I do otool -L on A.dylib, this is what I get :
A.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/homebrew/opt/gcc/lib/gcc/10/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.28.0)
/opt/homebrew/opt/gcc/lib/gcc/10/libgomp.1.dylib (compatibility version 2.0.0, current version 2.0.0)
Which means that if these two libraries aren't in there, the application won't launch at all. So my problem is with the installer, am I supposed to install libstdc++.6.dylib and libgomp.1.dylib in /opt/homebrew/opt/gcc/lib/gcc/10/ for the user? Even if they don't have a gcc installed there, or at all?
Another option is to install the libraries under say /Library/Application Support/, but then this would mean that the path A.dylib is linked to won't be correct anymore. How do I change the linking path automatically after I install those libraries? What is the best way to go beyond this?
I have installed Qt 5.4 on MacOSX Darwin Kernel Version 14.3.0 and
am trying to setup LLDB Debugger as GDB has been depurated from MacOSX (as i didn't found it as default).
When i am trying to setting up debugger option in Build & Run kit in Qt Creator following below steps mentioned in Qt Documentation :
Select Tools > Options > Build & Run > Kits.
Select an automatically created kit in the list, and then select
Clone to create a copy of the kit.
In the Debugger field, select an LLDB Engine.
If an LLDB Engine is not listed, select Manage to add
it in Tools > Options > Build & Run > Debuggers.
For more information, see Adding Debuggers. To use the debugger,
add the kit in the Build Settings of the project.
I am setting the Debugger as "/usr/bin/lldb" in the Build&Run Kit.
After following all the steps correctly as mentioned various forums when i try to set the breakpoint and run the Qt project in Debug mode it is not hitting the breakpoint.It running as "Run" option Not working like "DEBUG" Mode.
I have one small question or maybe asking for suggestion regarding following error which i resolved but i don't know whether its correct way to do that.
When trying to run an executable I've been sent in Mac OS X, I get the following error
dyld: Library not loaded: libLocalIPC.1.dylib
Referenced from: /Users/"Directory my executable is in"
Reason: image not found.
I fixed this issue with setting Environment DYLD_LIBRARY_PATH under Project Settings/Run Environment with the library path which points to debut version of library.So for Building my Application in Release i have to again set the Library Path with Release Library Path.So this solution is not correct.
Another Solution i tried before that was with using otool -L #executable_Path/XXX.exe and checking the path of dylib and changing it with,install_name tool of Xcode but it didn't worked also.
Example:
MacOS xxx$ otool -L check abc
libLocalIPC.1.dylib (compatibility version 1.0.0, current version 1.0.0)
libxxx.1.dylib (compatibility version 1.0.0, current version 1.0.0)
libqyyy.1.dylib (compatibility version 1.0.0, current version 1.0.0)
libzzz.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/spandey/Qt/5.4/clang_64/lib/QtWebEngineWidgets.framework/Versions/5/QtWebEngineWidgets (compatibility version 5.4.0, current version 5.4.1)
/Users/spandey/Qt/5.4/clang_64/lib/QtWebEngine.framework/Versions/5/QtWebEngine (compatibility version 5.4.0, current version 5.4.1)
/Users/spandey/Qt/5.4/clang_64/lib/QtQuick.framework/Versions/5/QtQuick (compatibility version 5.4.0, current version 5.4.1)
/Users/spandey/Qt/5.4/clang_64/lib/QtGui.framework/Versions/5/QtGui (compatibility version 5.4.0, current version 5.4.1)
After this i set the path to libs libxxx.1.dylib,libyyy.1.dylib & libzzz.1.dylib and again run the otool -L abc
Results :Administrators-Mac-Pro:MacOS spandey$ otool -L abc
abc:
/Users/spandey/Desktop/Perforce/launcher/xxx/libxxx.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/spandey/Desktop/Perforce/launcher/ThirdParty/yyy/lib_osx/libqyyy.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/spandey/Desktop/Perforce/launcher/ThirdParty/zzz/debug_osx/libzzz.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/spandey/Qt/5.4/clang_64/lib/QtWebEngineWidgets.framework/Versions/5/QtWebEngineWidgets (compatibility version 5.4.0, current version 5.4.1
MacOS xxx$ ./abc
dyld: Library not loaded: libzzz.1.dylib
Referenced from:
/Users/spandey/Desktop/Perforce/launcher/xxx/libxxx.1.dylib
Reason: image not found
Trace/BPT trap: 5
Please can some one help me in both the issues as i am trying this from last 3 days with no success.
I'm still quite new to Objective C and Xcode, but I just finished a small app that uses the openCV libopencv_core.2.4.2.dylib.
When I went to open the final built app on another machine, OS X threw me this error:
Dyld Error Message: Library not loaded: */libopencv_core.2.4.dylib
Referenced from: /Users/USER/Desktop/my
app.app/Contents/MacOS/my app
Reason: image not found
Why is my app looking for 2.4 instead of 2.4.2 here?
What I already checked:
I added a new build phase -> so that libopencv_core.2.4.2.dylib is copied to the app package (via "Copy Bundle Resources" in Xcode) - libopencv_core.2.4.2.dylib now lies in my app.app/Resources
What did I miss? Do I have so set some more library search paths or similar?
What I also did:
install_name_tool -id "#executable_path/../Frameworks/libopencv_core.2.4.2.dylib" libopencv_core.2.4.2.dylib
Copying the dylib to the Frameworks directory doesn't work either:
Library not loaded: #executable_path/../Frameworks/libopencv_core.2.4.2.dylib
Don't know what to do now - the dylib is in the Frameworks directory of my app...
Using otool -L on the binary gives me:
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
#loader_path/../Frameworks/libopencv_core.2.4.2.dylib (compatibility version 2.4.0, current version 2.4.2)
#loader_path/../Frameworks/libopencv_highgui.2.4.2.dylib (compatibility version 2.4.0, current version 2.4.2)
#loader_path/../Frameworks/libopencv_imgproc.2.4.2.dylib (compatibility version 2.4.0, current version 2.4.2)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.1.0)
/System/Library/Frameworks/CoreData.framework/Versions/A/CoreData (compatibility version 1.0.0, current version 407.7.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.33.0)
I had the same problem. i keep all .dylib in system root directory usr/lib it working fine. At the run time .o file not get .dylib file path then it gives an error.
I found a better solution: recompiling openCV in Xcode and set the #executable_path/../Frameworks in the build settings, for every .dylib you compile - now the .dylibs themselves always "know where they are".
Since other answers are not clear enough;
Assume your dylib files are located in /usr/local/opt/opencv3/lib
sudo ln -s /usr/local/opt/opencv3/lib/*.dylib /usr/local/lib
will solve this problem. Be aware that /usr/lib is protected by system in MacOS, thus you should use /usr/local/lib.
I'm trying to distribute cairo (1.10.2) with my application. I can create the necessarily dylibs using Homebrew but they are dependent on versions of other dynamic libraries that aren't present in OS X 10.5 (libfontconfig, libfreetype, and others located primarily in /usr/X11/lib).
I assume to solve this I want it to be using the dylibs in /Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib rather than the libraries in /usr/X11/lib. I've tried anything I could find for targeting cairo against the 10.5 SDK.
Setting MACOSX_DEPLOYMENT_TARGET environment variable to 10.5 (before calling brew or using Homebrew's ENV)
Setting SDKROOT environment variable to "/Developer/SDKs/MacOSX10.5.sdk" (before calling brew or using Homebrew's ENV)
Adding -mmacosx-version-min=10.5 to the CFLAGS, CXXFLAGS, and LDFLAGS in the Homebrew formula for cairo.
Adding -sysroot/-isysroot /Developer/SDKs/MacOSX10.5.sdk to the CFLAGS, CXXFLAGS, and LDFLAGS in the Homebrew formula for cairo.
Adding -I$(SDKROOT)/usr/X11/include and -I$(SDKROOT)/usr/X11R6/include to the CFLAGS and CXXFLAGS in the Homebrew formula for cairo.
Adding -L$(SDKROOT)/usr/X11/lib and -L$(SDKROOT)/usr/X11R6/lib to the LDFLAGS in the Homebrew formula for cairo.
While building cairo it has -I/usr/X11/lib on the gcc commands (with my options tacked on the end) so I imagine it's hitting that first. I'm not sure how to get rid of that so it uses my options. I thought isysroot would make it so the include and library paths were rerooted in the SDK but -isysroot doesn't seem to have any effect.
You should be able to use install_name_tool to change where cairo looks for its libraries. (I have no idea what cairo is. I'm assuming it's a dylib. If not, my confidence in this solution goes down considerably.)
Here's a made-up example that you should be able to adapt.
First, use otool -L to see which libraries cairo is using. In this example I'm working with libopencv_imgproc.2.3.1.dylib, but you'll use your cairo library's file name instead:
$ otool -L libopencv_imgproc.2.3.1.dylib
libopencv_imgproc.2.3.1.dylib:
lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
Then use install_name_tool -change to change whichever paths you need to change. The first parameter is the current library path, the second is the desired library path, and the third is the library file. I'm telling it to look for libz.1.dylib in /Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/ instead of /usr/lib:
$ install_name_tool -change /usr/lib/libz.1.dylib /Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libz.1.dylib libopencv_imgproc.2.3.1.dylib
Repeat this for every library whose path you need to change. otool -L shows us that the change was made:
$ otool -L libopencv_imgproc.2.3.1.dylib
libopencv_imgproc.2.3.1.dylib:
lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
/Developer/SDKs/MacOSX10.5.sdk/usr/X11/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
In my example (and perhaps in your application) my library expects to find itself somewhere other than my application bundle, so I need to change that as well with install_name_tool -id. I'm copying the library to my application bundle's Frameworks folder so I'm telling it to look there:
$install_name_tool -id #executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
You can put the install_name_tool invocations in a Run Script build phase. If you are copying the library into your application bundle's Frameworks folder, you should prepend the library name with $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/ to ensure that the script can find the library.