GH-Unit and Objective C++

712 Views Asked by At

I have an iPhone project that uses GHUnit to conduct unit testing. Recently, I've needed to implement complex numbers and overload some operators to ease the calculation of FFTs. The goal here was to create a clean way to perform an FFT without the overhead of all the possible functionality that libraries like FFTW uses, and in this sense, I could further customize the number of calculations I'd like to do in my FFT (so I reduce the complexity of factorizing this or that used in the traditional DFT).

In short, this is why I decided to implement my own FFT library in C++, rather than use FFTW. However, this has caused some problems with GHUnit. All of my production targets work correctly with the integration of my FFT library, but GHUnit refuses to work. Specifically, I get linker errors with things like GHComposeString. This only happens in my Unit Tests target. I'm wondering what this problem might be? At first, I suspected that this may be because of the differences in C vs C++ in how function names are mangled, but it doesn't seem to affect the rest of the project, just the GHUnit portions.

Any help with mixing C++ with GHUnit appreciated.

4

There are 4 best solutions below

0
On BEST ANSWER

This isn't really an answer, but I think you're on the right track with the name mangling. Mangling is done at link time. GHUnit, which inherits from OCUnit, is injected into the app's memory space at runtime by dyld. So, there could conceivably be some kind of issues with GHUnit/OCUnit regarding the mangling of your Obj-C++ files.

0
On

Are you wrapping your GHUnit includes with extern "C"?

That will prevent them being mangled.

Ideally, their headers should do offer this internally but not everyone thinks of their headers being used in C++:

#ifdef __cplusplus
extern "C" {
#endif

...// other content here

#ifdef __cplusplus
}  // end of scope of extern "C"
#endif
0
On

One (related) thing that has bitten me in the past is that .m files are (by default) compiled as Obj-C, while .mm files are compiled as Obj-C++.

This applies when you are mixing the two (Obj-C(++) and cpp), which, if you are doing iPhone development (in iOS), you probably are.

Double check that your Obj-C test files that are utilizing your FFT class have the .mm and not the .m extension.

0
On

Add -lstdc++ to "Other Linker Flags" in your testing target.