I've written a C++ program on OS X 10.9, and I'd like to distribute the executable file, but the program won't run on OS X 10.7. I get the error message Illegal instruction: 4
. Is there a way to compile my program on OS X 10.9 and have it work on previous versions of OS X, say 10.6 and greater? I'm not using Xcode, I'm using clang++ version 3.4 with OpenMP support (http://clang-omp.github.io). As a side note, I'd also like to distribute the OpenMP library with my program so that users don't have to install it themselves. How do I make the library work with older versions of OS X?
Note: When I use something like -mmacosx-version-min=10.6
during compilation I get several errors related to "Undefined symbols for architecture x86_64". For example, on this very simple program:
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
return 0;
}
Compiled as clang++ -o hello hello.cc -mmacosx-version-min=10.6
, I get the following error:
Undefined symbols for architecture x86_64:
"__ZNKSt3__16locale9use_facetERNS0_2idE", referenced from:
__ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m in hello-323147.o
"__ZNKSt3__18ios_base6getlocEv", referenced from:
__ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m in hello-323147.o
"__ZNSt3__14coutE", referenced from:
_main in hello-323147.o
"__ZNSt3__15ctypeIcE2idE", referenced from:
__ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m in hello-323147.o
"__ZNSt3__16localeD1Ev", referenced from:
__ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m in hello-323147.o
"__ZNSt3__18ios_base33__set_badbit_and_consider_rethrowEv", referenced from:
__ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m in hello-323147.o
__ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5flushEv in hello-323147.o
"__ZNSt3__18ios_base5clearEj", referenced from:
__ZNSt3__124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m in hello-323147.o
__ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD2Ev in hello-323147.o
__ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5flushEv in hello-323147.o
ld: symbol(s) not found for architecture x86_64
clang-3.4: error: linker command failed with exit code 1 (use -v to see invocation)