Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rednax

macrumors newbie
Original poster
Feb 16, 2009
3
0
Hello,

I have a problem which I have been struggling with for a while.

I have a Cocoa library which acts as a wrapper for a C++ library. C++ library is tested using a set of BOOST unit tests. The tests run normally under both debug and release modes.

In order to test the Cocoa wrapper I am using otest. Here is the strange part, the tests run normally in debug mode but fail in release mode. To make sure its not something in the code I've taken the tests content and compiled them as a separate Cocoa app which uses the wrapper code. This runs normally both under release and debug.

When otest fails I get a stack trace which makes little sense and ends with dyld_misaligned_stack_error.

Another strange thing that I've noticed is that when starting otest from a command line rather than from XCode if I point DYLD_LIBRARY_PATH and DYLD_FRAMEWORK_PATH to the Debug version of C++ library the tests pass. I have confirmed though that all my test code is being compiled with Release flags.

Any help would be greatly appreciated!

Thank you
 

Cromulent

macrumors 604
Oct 2, 2006
6,817
1,102
The Land of Hope and Glory
Generally speaking when something works in debug mode but fails in release mode it means that the optimisation the compiler performs is screwing with parts of your program.

To check if this is the case disable optimisation in your project release settings and then compile and rerun your tests. If it works you know what the problem is. If it still does not work you have eliminated one possible cause.

I seem to remember running into this in the past. I'll see if I can dig up my notes on how I fixed it.
 

rednax

macrumors newbie
Original poster
Feb 16, 2009
3
0
Thanks Cromulent. I've discovered that removing NDEBUG from C flags fixes this problem, but I don't understand why though.
 

rednax

macrumors newbie
Original poster
Feb 16, 2009
3
0
Found the reason for the problem. As usual it was something very simple, I forgot to add NDEBUG to release version of the C++ library, which means that asserts were compiled differently and I guess that caused the stack misalignment. Thanks for the help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.