1

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)
redcurry
  • 2,381
  • 2
  • 24
  • 38
  • It would help to actually mention the errors that you're getting from the linker as that's the blocking reason preventing you from compiling the code to work correctly on the older release - see http://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10 – Anya Shenanigans Jul 11 '14 at 22:13
  • Slightly off-topic but, since Mavericks was a free update... what percentage of your target audience still uses 10.6? – 3Dave Jul 11 '14 at 23:12
  • @DavidLively. Probably not many, but I get the same error using `-mmacosx-version-min=10.8` – redcurry Jul 11 '14 at 23:26

1 Answers1

0

Based on the date of your question I guess this was some sort of bug in that specific clang version. I've tried compiling your example with Xcode 6.4 and it compiles and links fine:

$ clang++ -o hello hello.cc -mmacosx-version-min=10.6
$ ./hello 
Hello, world!
$ clang++ -v
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

Don't have an older osx machine to test it though, just ran it on Yosemite.

Grzegorz Adam Hankiewicz
  • 7,349
  • 1
  • 36
  • 78