I have inherited a fairly large and complex software package written in both C and C++ which successfully builds on Mac OSX Lion using gcc:
$> gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
I have been tasked with getting this same package to build on OSX Mavericks using the default Mac compiler that comes with Command Line Tools.
$> gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
The OSX Lion build finishes to completion but the OSX Mavericks build fails with the following error:
Undefined symbols for architecture x86_64:
"_MRIsetVoxVal", referenced from ...
I have traced source of the error to a header file with the following code block:
#ifdef __cplusplus
float MRIgetVoxVal( const MRI *mri, int c, int r, int s, int f);
int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval);
void MRIdbl2ptr(double v, void *pmric, int mritype);
double MRIptr2dbl(void *pmric, int mritype);
#else
inline float MRIgetVoxVal(const MRI *mri, int c, int r, int s, int f);
inline int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval);
inline void MRIdbl2ptr(double v, void *pmric, int mritype);
inline double MRIptr2dbl(void *pmric, int mritype);
#endif
If I modify the above code block by simply removing the if else
and inline
statements so that it looks like the following, then the build finishes to completion on both platforms:
float MRIgetVoxVal( const MRI *mri, int c, int r, int s, int f);
int MRIsetVoxVal(MRI *mri, int c, int r, int s, int f, float voxval);
void MRIdbl2ptr(double v, void *pmric, int mritype);
double MRIptr2dbl(void *pmric, int mritype);
So it appears that on OSX Lion, the ifdef __cplusplus
statement is triggered which produces the desired behavior. And on Mavericks the else
statement is triggered which ultimately results in a error.
Pardon me if this is a very basic question, but C and C++ are outside my area of expertise. What is going on here? What does #ifdef __cplusplus
even mean, and why does one version of gcc get triggered by it and the other does not?