PDA

View Full Version : Problem running otest in Release mode




rednax
Feb 16, 2009, 01:36 PM
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
Feb 17, 2009, 03:06 AM
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
Feb 17, 2009, 09:45 AM
Thanks Cromulent. I've discovered that removing NDEBUG from C flags fixes this problem, but I don't understand why though.

rednax
Feb 17, 2009, 12:16 PM
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!

Cromulent
Feb 17, 2009, 12:24 PM
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!

No worries, glad you solved your problem.