tags:

views:

547

answers:

2

I'm trying to use a C++ library (CLucene) from my Cocoa Touch iPhone application using Xcode 3.1.3. Everything works fine when I run in the iPhone simulator, but things get strange when I run on device. It seems like pointers aren't being passed correctly from the Objective-C++ code (my app) to the C++ library (CLucene).

While debugging the app on device, I can watch a const char* variable passed as a parameter to a C++ function change from 0x12546c0 in Objective-C++ to 0x4e in C++. Since 0x4e doesn't point to a valid const char*, the C++ code fails. This doesn't happen when debugging in the simulator.

I'm compiling the C++ library directly into the app, not linking to a static or dynamic lib.

Any help would be much appreciated.

A: 

There should be no problem using C++ code in an iPhone App (I do it all the time).

Pointers should just be passed as pointers without any interpretation.
Are you sure the Objective-C++ object is a 'const char*' and not some other type that is being converted (incorrectly) into a 'const char*' on the fly at run-time?

Martin York
Yes, I create the char array. The value is actually a const char* and not being converted at run time.
Jeremy Bower
+2  A: 

Disabling "Compile for Thumb" in the project's build settings fixes the problem.

Jeremy Bower
Really? I've heard that can speed up programs that use a lot of floats. But I wouldn't have expected this answer to your question.
Nosredna
I've heard the same thing about speeding up code, but in this case I can reproduce the problem by enabling "Compile for Thumb". I'm not sure why that's the case, or why it only happens when linking to this C++ code, but it clearly has some impact.
Jeremy Bower