Command line standalone app - run on other Macs

Is there a way to make a Command Line Tool (C++) to build with all its dependencies so it could run on another Mac without having to install any additional libs. I have a basic command line app that uses the OpenCV libraries. It can't run on other Macs because the dylib are not installed. I have all of the static libs (.a files) listed under " Build Phases->Link Binary With Libraries".


How do I make the final executable include all it needs to run on another Mac?


Running Xcode Version 9.0 (9A235), OS X 10.12.6, OpenCV 3.3 (installed with brew).

well i do this all the time but not from xcode or using homebrew or macports for ffmpeg.


i don't think apple ships any common backwards compatible libs like M$ but i could be wrong, so don't count on any dylibs


i use bash/vi and make/chop/hack the makefile/configure/cmake files as needed.


basically you need to sandbox and build out of tree and create static versions of the libs you app needs.


1. sandbox - use no default or system libs,

2 configure pkgconfig to build only static libs

3 build every lib/dependency you need

4 grab a cup of coffee this could take a while, watch the latest episode of Z-Nation or something

5 create tarball

6 distribute

7 watch next episode The Walking Dead, more coffee

Hello joe31093,

You have to use the -l linker flag and manually specify the full path to each library. See this tech note: developer.apple.com/library/content/qa/qa1393/_index.html

Hi John, thanks for the reply. Here is what I tried.


Under Build Settings -> Other Linker Flags, if I do:


-l:/usr/local/lib/libopencv_calib3d.a (build fails with "ld: library not found for -l:/usr/local/lib/libopencv_calib3d.a")


-lopencv_calib3d -lopencv_core -lopencv_features2d (and so on with the rest of the libs, it builds but still does not run on another machine)


If I remove the symlinks for the dylib out of the /usr/local/lib directory (where the rest of the .a libs are), I get Undefined symbols for architecture errors...


My Library Search Paths is set to /usr/local/lib


Still no luck.

Hi iPad_dev,


Not sure I know how to do everything you listed expect for maybe steps 4 and 7. I did end building my sources with with cmake. In my CMakeLists.txt, I call out the specific static libs that I needed and was able to build the program successfully. But I was still unable to run the program on another machine.


CMakeLists.txt specific libs that was included.


target_link_libraries(ScopeControl

libopencv_calib3d.a

libopencv_core.a

libopencv_dnn.a

libopencv_features2d.a

libopencv_flann.a

libopencv_highgui.a

libopencv_imgcodecs.a

libopencv_imgproc.a

libopencv_ml.a

libopencv_objdetect.a

libopencv_photo.a

libopencv_shape.a

libopencv_stitching.a

libopencv_superres.a

libopencv_video.a

libopencv_videoio.a

libopencv_videostab.a)

You have to specify the full path to the library and only the full path. If you add random characters like colons, the linker isn't going to be able to find the files.


I wouldn't recommend just moving the dylibs because such hacks are sure to cause problems. If you are getting a specific errors, it is really, really helpful to include the text and context of that error. It is possible that the linker is using the static libraries but those libraries don't have the correct architectures. Or maybe it just isn't using the static libraries.


Is this just a one-time thing? Or is this part of some project you are going to be posting on the internet or something? There are many other factors to consider that I haven't brought up. Just because you get it working doesn't mean you're done.

Maybe you can clearify for me how do you set the full path of the static lib in Xcode. I used the following notations (plus the : option as well) under Other Linker Flags. The library is located in /usr/local/lib/libopencv_calib3d.a.


-l/usr/local/lib/libopencv_calib3da.a results in:

ld: library not found for -l/user/local/lib/libopencv_calib3d.a

clang: error: linker command failed with exit code 1 (use -v to see invocation)


-L/usr/local/lib/libopencv_calib3da.a results in:

ld: warning: directory not found for option '-L/user/local/lib/libopencv_calib3d.a'


Everything built fine and it runs. The arch is set to x86_64. If it wasn't the right arch, I would expect it not to build the final binary due to unresolved externals/undefined arch errors. This is not a one time thing. We are trying to make apps that will run on other machines in the lab.

I think the first thing to do would be to figure out why you are typing both "/usr" and "/user". If that is really output from Xcode, then you've got a royal mess on your hands. If you are re-typing, can you include Xcode's exact output?


If this is a lab environment, then it probably makes more sense to just install the dependencies in the lab. It is a bit of a hassle, but you would been done by now.

Usr/user typo. Here is the output.


Ld build/Debug/ClientConnection normal x86_64

cd "/Users/jli1/Documents/Git Repo/main/Source/Xcode Projects/ClientConnection"

export MACOSX_DEPLOYMENT_TARGET=10.12

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -L/Users/jli1/Documents/Git\ Repo/main/Source/Xcode\ Projects/ClientConnection/build/Debug -L/usr/local/lib -L/usr/local/Cellar/opencv/3.3.1_1/lib -F/Users/jli1/Documents/Git\ Repo/main/Source/Xcode\ Projects/ClientConnection/build/Debug -filelist /Users/jli1/Documents/Git\ Repo/main/Source/Xcode\ Projects/ClientConnection/build/ClientConnection.build/Debug/ClientConnection.build/Objects-normal/x86_64/ClientConnection.LinkFileList -mmacosx-version-min=10.12 -Xlinker -object_path_lto -Xlinker /Users/jli1/Documents/Git\ Repo/main/Source/Xcode\ Projects/ClientConnection/build/ClientConnection.build/Debug/ClientConnection.build/Objects-normal/x86_64/ClientConnection_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -l/usr/local/lib/libopencv_calib3d.a -lopencv_superres -lopencv_video -lopencv_imgcodecs -lopencv_videoio -lopencv_objdetect -lopencv_core -lopencv_photo -lopencv_stitching -lopencv_videostab -lopencv_shape -lopencv_calib3d -lopencv_ml -lopencv_dnn -lopencv_imgproc -lopencv_flann -lopencv_highgui -lopencv_features2d -Xlinker -dependency_info -Xlinker /Users/jli1/Documents/Git\ Repo/main/Source/Xcode\ Projects/ClientConnection/build/ClientConnection.build/Debug/ClientConnection.build/Objects-normal/x86_64/ClientConnection_dependency_info.dat -o /Users/jli1/Documents/Git\ Repo/main/Source/Xcode\ Projects/ClientConnection/build/Debug/ClientConnection


ld: library not found for -l/usr/local/lib/libopencv_calib3d.a

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Review that quasi-link I posted above (Apple censors live links. I don't know if they censor links to their own sites or not. I didn't want to take the chance).


You have to provide "-Wl" to pass the "-l" option directly to the linker. There are other options you can use to control which directories to search.

Command line standalone app - run on other Macs
 
 
Q