Embed libraries into package - macos

I have a Cocoa application that uses OpenCV, TBB, boost and some other libraries which are installed in my system. How do I create a package that has all this inside so that customer doesn't have to install anything besides just copy/paste my package?
At the building stage they are referenced via .dylib .
Is it possible?
Where I choose in xCode Product\Archive it will only export the app itself.

well, after a lot of reading I could not find an easy solution. Maybe is there, but I didn't have more time to search for it.
So instead I wrote a small application in C++ that uses otool and install_name_tool utilities to analyze needed required libraries and copy them into the bundle. Is located here https://github.com/integral-llc/libb . Keep in mind, it was made for personal use, but can be easily changed for anything else.
It worked perfectly for my case. It found all needed dependencies for OpenCV, boost, TBB.
if you have better tools or ideas to improve current one, you are more than welcome to say.

Related

Racket/Scheme compile to single binary, no dependencies? FFI and static linking

Say I'm building an app in Racket.
And say eventually I want to compile that app as a single binary file that could be distributed to users, without them having Racket or any other software libs installed. I believe this is possible, yes?
Say in that app I want to use the snappy package https://docs.racket-lang.org/snappy/ which is some FFI wrappers around a C++ lib.
I already ran into a minor problem. I did (require snappy) inside DrRacket and followed the prompts and got the package installed but I get the error:
../../Applications/Racket v7.7/collects/racket/private/kw.rkt:1349:57:
ffi-lib: couldn't open "libsnappy.1.dylib" (dlopen(libsnappy.1.dylib, 6): image not found)
I can assume from this that racket-snappy expects the files for libsnappy to be on the usual unix path, but I'm on macos and mine is installed via Homebrew somewhere else. I believe the answer to that problem is here https://stackoverflow.com/a/24287418/202168
My concern is: I do not want users of my app to have to install these libs via Homebrew and fiddle with paths etc.
I am a Racket noob and know basically nothing about the compiler toolchain or C/C++ for that matter either. But I believe what I need is when I compile my Racket project to be able to have raco exe(?) "statically link" the libsnappy that's on my system and roll everything into a single binary with no dependencies.
So my question is: is this possible? If so, is it straightforward (i.e. managed via raco tools)?
I'm imagining in the worst case I have to download all the dependencies and build them from source and build my Racket project also as a library and then have some kind of skeleton C project that pulls them all in into one thing. I hope not.
I will add also... if this is easier in other Schemes (Chicken? Chez? Gambit? Guile?) then I'd be interested to know too.
Update: I found this article with some year-old anecdata of someone attempting the same thing https://taoofmac.com/space/blog/2019/06/20/2310
Based on that, and Ryan's answer below, raco distribute looks promising and I really need to try this out for myself to confirm what works.
Update again: Here is another article again confirming raco distribute should put everything into a folder with no external deps https://defn.io/2020/06/28/racket-deployment/ and here is a pointer to the docs for how to build a .dmg image for MacOS: https://docs.racket-lang.org/raco/exe-dist.html#(part._.A.P.I_for_.Bundling_.Distributions)
There is a partial solution using a combination of raco distribute and define-runtime-path.
Suppose you have a program that uses libzmq, which you know is installed on your build system at /usr/lib/x86_64-linux-gnu/libzmq.so.5. You can use define-runtime-path to create a reference to that file and tell raco distribute to copy it to the distribution directory. For example, suppose that "my-app.rkt" is the following:
#lang racket/base
(require racket/runtime-path)
(define-runtime-path zmq "/usr/lib/x86_64-linux-gnu/libzmq.so.5")
(printf "zmq = ~e\n" zmq)
When you run the program using racket my-app.rkt, it prints
zmq = <path:/usr/lib/x86_64-linux-gnu/libzmq.so.5>
But when you run raco exe my-app.rkt and then raco distribute MyApp my-app, then the MyApp directory will contain a copy of libzmq.so.5:
$ find MyApp/ -type f
MyApp/lib/plt/my-app/exts/ert/r0/libzmq.so.5
MyApp/lib/plt/racket3m-7.7
MyApp/bin/my-app
and if you run ./MyApp/bin/my-app, it prints
zmq = #<path:/PATH/TO/HERE/./MyApp/bin/../lib/plt/my-app/exts/ert/r0/libzmq.so.5>
You can use (ffi-lib zmq) to load the shared library. Unfortunately, that directory is not in the search path that the application will use for loading shared libraries, so existing Racket libraries that just try to load (ffi-lib "libzmq" '("5")) won't find the application's copy.
There is another way of using define-runtime-path specifically for shared libraries, and I thought it would solve that problem, but it doesn't seem to. That seems like a bug to me, so I'll file a bug report.
Update: I have filed a bug report about the fact that define-runtime-path's shared library ('so) mode causes raco distribute to copy the shared library outside of the application's library search path.

How to Publish/Export wxWidgets Application

newbie here.
Want to ask for any advice on how to Publish/Export, CodeBlocks Application made by using wxWidgets. After some research, i discovered that i should use DLL, or something like that, but since I am really new into it, I am missing the logic on how I should actually implement that. Since CodeBlocks offers wxWidgets and DLL as separate projects. So I am not really sure how to properly combine. Thanks in advance.
If you used wxWidgets as .dll, to get a self-standing package you have to distribute all the requested libraries. The simplest way is just to copy them from their source folder (in your case [wxWidgets root]\lib\gcc_dll) in the same folder as your executable. There could be many of them, but usually only two or three are needed. For simplicity you can copy them all, or you can try repeatedly to start the program, and add each time the library indicated in the error message.
Please note that to distribute your application you will probably want to compile it in Release mode, and consequently you should ship the Release .dlls (i.e. beginning with wx...28_ instead of wx...28d_).

Proper way to link against libraries with dependencies?

I'm working on a fairly simple OS X app that uses a couple third-party libraries (SoX and TwoLAME) to do some audio converting. TwoLAME relies on libsndfile, and SoX relies on sndfile plus a number of other libraries.
For development, I simply installed the two libraries with Homebrew, which took care of the dependencies, and then linked right to them (ie in /usr/local/Cellar/...). Now that I'm ready to deploy, I need to figure out a way to get everything packaged up.
I know frameworks are a bit ambiguous in Cocoa (fake ones, dynamic ones, etc), but it seems like ideally I would end up with some frameworks of one kind or another that I can drop into the project and everything would work.
I've read through a lot of different docs and tutorials about frameworks, and tried a number of approaches, but I seem to be missing some core concept for getting this all to work together.
I have been able to make frameworks from the libraries that sort of work, in the sense that I compile from source, take the static (.a) library and put it in a "fake" framework with the headers, and the app will run with those. Those static libraries are still referencing the dependencies on my local path, though. So, eg, if I uninstall Lame from Homebrew, the SoX static library in my framework will fail.
I'm really struggling to figure out what the best way cleanly get all these libraries and their dependencies into this app. The tutorials I've seen about building dynamic Cocoa libraries from scratch have been very hard to do with the source code for these pre-existing libraries. The other option I have considered it build dylibs and then use install_name_tool to change paths to be relative just ship everything with the app and try to match everything up.
There's got to be some better way that I'm just missing, and would really appreciate any help.

wxWidgets and Golang

I want to develop a programm in Go with a multi-OS GUI in wxWidgets, my dev environment is WinXP x86.
I wanted to use the wxWidgets Go wrapper wxGo, but the documentation is very succint and the project seems dead since 2 years.
I encountered some errors with the go get github.com/JeroenD/wxGo and go install github.com/JeroenD/wxGo
Result of go get github.com/JeroenD/wxGo:
package github.com/JeroenD/wxGo
imports github.com/JeroenD/wxGo
imports github.com/JeroenD/wxGo: no Go source files in C:\Documents and Settings\dell\Mes documents\gopath\src\github.com\JeroenD\wxGo
Result of go install github.com/JeroenD/wxGo:
can't load package: package github.com/JeroenD/wxGo: no Go source files in C:\Documents and Settings\dell\Mes documents\gopath\src\github.com\JeroenD\wxGo
I tried to follow the Building.txt doc from JeroenD's github. First time, I downloaded and installed wxWidgets, the sample codes were able to compile (with MinGW), but I was not able to compile the wxWidgets library from source. The second time, I downloaded and installed wxPack, with libs/dll already compiled. Here, the problem is I can't compile the wxWidgets samples.
As stated in the Buiding.txt doc from JeroenD's github, I installed SWIGWIN, but did not compile it from source as SWIG now supports Go (from SWIG's documentation). But now, I don't know what to do with a wrapper (wxGo), wxWidgets dll/libs, and SWIG. I think I read that SWIG needs *.i files to make bindings from language to another, but I can't find any in my wxWidgets folder, perhaps I have to take these files from another wxWidgets binding (wxLua and wxPython have these in their repos).
My goal is just to get the wxWidgets lib working with Go to be able to write a multi OS GUI in wxWidgets, I'm a bit surprised that nobody had posted problems with JeroenD's package nor wanted to get wxWidgets working with Go.
As you may ask, building a gtk GUI with go-gtk is not a solution, as it is needed in my project to have a multi-OS GUI looking OS native (if you have a multi-OS GUI lib which looks native and is simpler to use, please tell me).
According to the Building.txt file:
To build the wxGo library:
cd wx
make install
So, despite this being a Go package, it doesn't seem to use any actual Go code (if you look in github.com/JeroenD/wxGo you won't see any .go files).
I think, in cases like this, you need to use git (instead of go get) and make install instead of go install.
On windows you may want to get the Git for Windows installer to make this process a bit simpler.
Once it's built it looks like you can use
import "wx"
as usual in your go code (minimal example at https://github.com/JeroenD/wxGo/blob/master/example/minimal/minimal.go)
wxGO wxWidgets wrapper for GO is live here wxGO MultiOS
QML may be a better choice, it helps deal with wxWidget or QT underwear.

Getting QMake to generate a proper .app

I have a large exiting C++ project involving:
4 applications
50+ libraries
20+ third party libraries
The project uses QMake (part of Trolltech's Qt) to build the production version on Linux, but I've been playing around at building it on MacOS.
I can build in on MacOS using QMake just fine but I'm having trouble producing the final .app. It needs collecting all the third party frameworks and dynamic libraries, all the project's dynamic libraries and making sure the application finds them.
I've read online about using install_name_tool but was wondering if there's a process to automate it.
(Maybe the answer is to use XCode, see related question, but it would have issues with building uic and moc)
Thanks
I'm sure this could be of some great help for you :
deployqt
Hope this helps !
We have the same problem at Last.fm, I looked at DeployQt and it's not much use if you have third party libraries. In the end I wrote a perl script that generates a Makefile, which you can use to generate a .app and/or .dmg.
I uploaded it here: http://www.methylblue.com/detritus/QMake.dmg/
To use it add this to your application's pro file:
macx*:!macx-xcode:release {
system( QT=\'$$QT\' QMAKE_LIBDIR_QT=\'$$QMAKE_LIBDIR_QT\' $$ROOT_DIR/common/dist/mac/Makefile.dmg.pl $$DESTDIR $$VERSION $$LIBS > Makefile.dmg )
QMAKE_EXTRA_INCLUDES += Makefile.dmg
}
I'm sure it's not all yet portable, but it would be good for someone else to use and see if that is so.
This is basically the first official release of this code, so please send me bug reports, and also, improvements. Thanks.
I side-stepped this problem completely by building my Qt app statically on OS X. That might not be practical for you though.

Resources