Bug 15107 - Objective-C++ test fails during configure: conftest.mm broken on 10.8.x
Objective-C++ test fails during configure: conftest.mm broken on 10.8.x
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Installation
R 2.15.1 patched
All Mac OS X v10.8
: P5 minor
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-14 04:00 UTC by Charlie Sharpsteen
Modified: 2013-01-17 18:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Charlie Sharpsteen 2012-11-14 04:00:02 UTC
R searches for an Objective-C++ compiler by trying to compile the following test program (defined under `R_PROG_OBJCXX` in `m4/R.m4`):


#include <objc/Object.h>
#include <iostream>

@interface Greeter : Object
- (void) greet: (const char *)msg;
@end

@implementation Greeter
- (void) greet: (const char *)msg { std::cout << msg; }
@end

int
main ()
{
  std::cout << "Hello from C++\n";
  Greeter *obj = [Greeter new];
  [obj greet: "Hello from Objective-C\n"];
}


On 10.7.x under XCode 4.5.2 this passes with a warning:


$ clang++
conftest.mm:16:18: warning: class method '+new' not found (return type defaults to 'id')
  Greeter *obj = [Greeter new];
                 ^~~~~~~~~~~~~
1 warning generated.


On 10.8.x under XCode 4.5.2 it fails with an error:


$ clang++ -c conftest.mm
conftest.mm:4:22: error: cannot find interface declaration for 'Object', superclass of
      'Greeter'
@interface Greeter : Object
~~~~~~~~~~~~~~~~~~   ^
conftest.mm:16:18: warning: class method '+new' not found (return type defaults to 'id')
  Greeter *obj = [Greeter new];
                 ^~~~~~~~~~~~~
1 warning and 1 error generated.


Similar warnings and errors are generated if `g++` is used instead of `clang++`. If one passes the `-U__OBJC2__` flag during compilation, the errors and warnings disappear and the test compiles successfully.

An examination of `/usr/include/objc/Object.h` shows that this is an empty header file on 10.8.x unless the preprocessor variable `__OBJC2__` is undefined.
Comment 1 Charlie Sharpsteen 2012-11-14 05:08:23 UTC
Also, the `R_PROG_OBJC_RUNTIME` test fails in the same way for the same reason: `objc/Object.h` is a no-op include on OS X 10.8.x unless `__OBJC2__` is undefined.
Comment 2 Brian Ripley 2012-12-03 17:39:54 UTC
No patch was provided so this needs a developer using OS 10.8.  I will have such a system shortly.
Comment 3 Brian Ripley 2013-01-02 14:53:47 UTC
Code changed, minimally tested.
Comment 4 Brian Ripley 2013-01-17 18:18:37 UTC
Confirmed on a vanilla 10.8 system.