# OS X: Crash running program compiled on a different Mac

**URL:** <https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92>\
**Category:** support\
**Created:** [September 17, 2014, 6:06pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92 "2014-09-17T18:06:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 17, 2014, 6:06pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/1 "2014-09-17T18:06:35Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Wednesday, September 17, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#d047):

Hi there, my development machine is a MacBook Air (OS X 10.9.4). I compiled a simple test program using the static GLFW 3.0.4 library (installed using `brew install --static glfw3`) with Xcode 5.1.1.

When I copy even the simplest test program to another machine (an older iMac with Radeon 4670 graphics, but also running OS X 10.9.4), it crashes with the following message:

```
Illegal instruction: 4

```

The crash happens during the glfwInit() call. I can’t get more details or a stack trace, because I don’t have developer tools installed on the “user” machine (I want it to be a non-dev machine, on which I can test-deploy my app). I know that the Radeon 4670 only supports up to OpenGL 3.3 under OS X 10.9, but since I haven’t even gotten to the point of creating a window/context, I think that’s irrelevant.

Anyone have any ideas on how to proceed? Again, both machines are running OS X 10.9.4. One is an i5, the other an older i3.

Thanks,  
Glen.

P.S. My “simplest test program” can be just:

```
#include <GLFW/glfw3.h>
int main()
{
    glfwInit();
    glfwTerminate();
    return 0;
}

```

And to compile:

```
c++ -o test test.cpp -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 17, 2014, 8:33pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/2 "2014-09-17T20:33:23Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Wednesday, September 17, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#2801):

I managed to run the program on another OS X 10.9.4 machine (also an older iMac, but with developer tools installed). Using gdb, I was at least able to see that the crash is in \_glfwPlatformInit() (EXC\_BAD\_INSTRUCTION, Illegal instruction/operand), called by glfwInit().

Does this mean that my brew version of GLFW is using (OS or CPU) features that are not available on slightly older machines?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 17, 2014, 8:35pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/3 "2014-09-17T20:35:22Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Wednesday, September 17, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#47e1):

That’s possible, depending on what flags were used for compilation.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 17, 2014, 10:00pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/4 "2014-09-17T22:00:44Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Wednesday, September 17, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#2c98):

Okay, seems I’ve figured this out (not the exact cause, but at least a solution!). Seems I was barking up the wrong tree, at least a bit. I had copied the executable onto a memory stick that was FAT32 formatted, so it didn’t keep the OS X permissions (and possibly other file metadata?). Even though the file was executable on the other OS X machine, somehow it didn’t work, always crashing on glfwInit(). Something got “lost” in the copy.

If I tar up the file and transfer it that way, it no longer crashes.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [September 18, 2014, 3:04pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/5 "2014-09-18T15:04:43Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Thursday, September 18, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#27f0):

Interesting bug. Thank you for the follow-up!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 4, 2014, 1:56pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/6 "2014-11-04T13:56:00Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Tuesday, November 04, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#bf4c):

Well, I spoke too soon. I am still having the original problem (crash with `Illegal instruction: 4`). It happens when running a simple test program (such as the one above), now compiled on a 10.9.5 machine and trying to run on a non-developer 10.9.5 machine. It happens even when I tar up the file and it has correct permissions.

Any ideas where else I could look? I’m linking with the static `libglfw3.a`, installed using brew. I’m now using Xcode 6.1 (i.e. compiling with Apple LLVM version 6.0 (clang-600.0.54)). I tried uninstalling and reinstalling glfw3, so that it is also built and linked with the same version of the compiler, but it doesn’t solve the crash.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 4, 2014, 2:38pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/7 "2014-11-04T14:38:21Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Tuesday, November 04, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#9c70):

Have you looked at [these](https://stackoverflow.com/questions/10177038/illegal-instruction-4-shows-up-in-os-x-lion) [threads](https://stackoverflow.com/questions/14268887/what-is-the-illegal-instruction-4-error-and-why-does-mmacosx-version-min-10)?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 4, 2014, 4:09pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/8 "2014-11-04T16:09:55Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Tuesday, November 04, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#dfa0):

Thanks for the links, it’s helpful to learn more debugging tricks (like `dtruss`). I’ve tried various suggested things, such as compiling with `-mmacosx-version-min=10.6` (which doesn’t make much sense, since all my machines are on the same OS revision).

In the end, I discovered that if I compile on a MacBook Air, it runs fine on the slightly older iMac (all machines running 10.9.5). The problem occurs when I _compile on a new Mac Pro_ and try to run on the iMac. Something to do with the architecture? In both cases, running `file` on the executable indicates

```
test: Mach-O 64-bit executable x86_64

```

I’ve tried building a universal version of GLFW, and my app, on the Mac Pro (Xeon E5), but it still crashes when running on the other machine (Core i3). I even tried compiling/linking both GLFW and my program with `-arch i386` for the 32-bit version, and it **still** gives me the `Illegal instruction: 4` error with the executable built on the Mac Pro!

Do some Xeon-only optimisations get enabled by default with the compiler? How do I turn them off?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 5, 2014, 1:48pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/9 "2014-11-05T13:48:36Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Wednesday, November 05, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#2bf5):

Further update: it _works_ if I build GLFW locally (not using brew), then link with that static library.

It always crashes (in `_glfwPlatformInit()`) with a brew-built `glfw3` version (built on my Mac Pro, test program running on an older iMac). The compilation and linking flags for both brew and regular cmake runs look the same… Mystified.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 5, 2014, 2:14pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/10 "2014-11-05T14:14:43Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Wednesday, November 05, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#6f71):

This is not related to GLFW, then, but to instruction set compiler flags vs. an old CPU.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 5, 2014, 5:43pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/11 "2014-11-05T17:43:27Z")

</div>

**[totalgee](https://sourceforge.net/u/totalgee/)** wrote on [Wednesday, November 05, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#d2e4):

Thanks, Camilla, you’re right (but the problem was I didn’t know how to fix it). I got a reply from the brew folks, though, and now the problem is solved. I needed to build/install GLFW using their “build-bottle” option, which builds projects using a more compatible set of flags:

```auto
$ brew install glfw3 --static --build-bottle

```

This solves my crash. If anyone is interested, the answer is [here](https://github.com/Homebrew/homebrew-versions/issues/563#issuecomment-61832886).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 5, 2014, 5:45pm UTC](https://discourse.glfw.org/t/os-x-crash-running-program-compiled-on-a-different-mac/92/12 "2014-11-05T17:45:57Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Wednesday, November 05, 2014](https://sourceforge.net/p/glfw/discussion/247562/thread/e145b4d4/#8c0c):

Thank you for the follow-up! I’ll find a place for this in the documentation.
