I wrote a piece of C code on OS X 10.9.2 (Mavericks) and compiled it using the gcc compiler from terminal by linking the required libraries (like -lm -lfftw3 etc.). It works fine on my computer and another running the same OS (that also has the required libraries) but when I tried running the executable on another computer running OS X 10.8 (Mountain Lion), it doesn't work. I didn't try recompiling on the computer running OS X 10.8 (Mountain Lion) because it doesn't have the required libraries installed. How can I create a new executable using only terminal on my computer (running OS X 10.9.2 (Mavericks)) so that it works on any previous version of the OS that may never have the required libraries installed?
Thanks.
There are three approaches to this problem:
libm
(math library) exists on all systems typically, so it's like just libfftw3
and other libraries that need to be rebuilt.<www.macports.org>
Edit:
In response to your ocmment, you can force static linking of dependencies for your XCode target, in the case of libfftw3
, by replacing the line:
-lfftw3
With:
-l/full/path/to/libfftw3.a
Repeat this for all of the libraries against which your target links, and you're set. The final application binary will likely be much greater in file size, but completely self contained.
References:
<https://stackoverflow.com/questions/458805/force-static-linking-of-library-linked-to-xcode-target>
<https://stackoverflow.com/questions/22391848/compiling-a-c-program-for-previous-os-x-version>