I am teaching myself objective-c and I want to test objective-c++. I compiled objective-c using /usr/local/GNUstep/System/Library/Makefiles/GNUstep.sh and after
- with clang
- with gcc
When I try to compile objective c++
get this error.
I am using this example:
https://gist.github.com/752184
- with clang
- error
- with gcc
- error
Any idea?
- with clang
Code:
clang -ObjC hello.m -o hello `gnustep-config --objc-flags`
-I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include
-fconstant-string-class=NSConstantString -I/usr/local/GNUstep/System/Library/Headers
-L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib -lgnustep-base
- with gcc
Code:
gcc42 hello.m -o hello `gnustep-config --objc-flags`
-I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include
-fconstant-string-class=NSConstantString -I/usr/local/GNUstep/System/Library/Headers
-L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib -lgnustep-base
When I try to compile objective c++
Code:
I
I am using this example:
https://gist.github.com/752184
Code:
#include <iostream>
#import <Foundation/Foundation.h>
class MyCppNSStringWrapper
{
public:
MyCppNSStringWrapper(const char* str);
virtual ~MyCppNSStringWrapper();
unsigned int length() const;
short characterAtIndex(unsigned int index) const;
const char* UTF8String() const;
private:
NSString* _internal;
};
MyCppNSStringWrapper::MyCppNSStringWrapper(const char* str)
{
_internal = [[NSString alloc] initWithCString:str
encoding:NSUTF8StringEncoding];
}
MyCppNSStringWrapper::~MyCppNSStringWrapper()
{
[_internal release];
_internal = nil;
}
unsigned int MyCppNSStringWrapper::length() const
{
return [_internal length];
}
short MyCppNSStringWrapper::characterAtIndex(unsigned int index) const
{
return [_internal characterAtIndex:index];
}
const char* MyCppNSStringWrapper::UTF8String() const
{
return [_internal UTF8String];
}
extern "C" int main(int argc, char** argv)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
MyCppNSStringWrapper* s = new MyCppNSStringWrapper("Hello World!");
std::cout << "The string length is " << s->length() << std::endl;
std::cout << "The string third char value is " << s->characterAtIndex(2) << std::endl;
std::cout << "The string is " << s->UTF8String() << std::endl;
[pool release];
return 0;
}
- with clang
Code:
clang -ObjC++ 1.mm -o 1 `gnustep-config --objc-flags`
-I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include -fconstant-string-class=NSConstantString
-I/usr/local/GNUstep/System/Library/Headers -L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib
-lgnustep-base
- error
Code:
In file included from 1.mm:8:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:33:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/FoundationErrors.h:29:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObject.h:30:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:95:
In file included from /usr/local/GNUstep/System/Library/Headers/GNUstepBase/GSObjCRuntime.h:62:
/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include/objc/objc-api.h:488:10: error: cannot initialize return object of type 'MetaClass'
(aka 'objc_class *') with an rvalue of type 'Class'
return CLS_ISCLASS(_class)?_class->class_pointer:Nil;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include/objc/objc-api.h:298:26: note: expanded from:
#define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
^
/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include/objc/objc-api.h:576:10: error: cannot initialize return object of type 'MetaClass'
(aka 'objc_class *') with an rvalue of type 'Class'
return ((object!=nil)?(CLS_ISCLASS(object->class_pointer)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from 1.mm:8:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/Foundation.h:33:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/FoundationErrors.h:29:
In file included from /usr/local/GNUstep/System/Library/Headers/Foundation/NSObject.h:30:
/usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:147:20: error: use of undeclared identifier 'INTPTR_MAX'
enum {NSNotFound = NSIntegerMax};
^
/usr/local/GNUstep/System/Library/Headers/Foundation/NSObjCRuntime.h:45:24: note: expanded from:
# define NSIntegerMax INTPTR_MAX
^
1.mm:13:1: error: expected member name or ';' after declaration specifiers
����MyCppNSStringWrapper(const char* str);
^
1.mm:14:1: error: expected member name or ';' after declaration specifiers
����virtual ~MyCppNSStringWrapper();
^
1.mm:15:1: error: expected member name or ';' after declaration specifiers
����unsigned int length() const;
^
1.mm:16:1: error: expected member name or ';' after declaration specifiers
����short characterAtIndex(unsigned int index) const;
^
1.mm:17:1: error: expected member name or ';' after declaration specifiers
����const char* UTF8String() const;
^
1.mm:19:1: error: expected member name or ';' after declaration specifiers
����NSString* _internal;
^
1.mm:22:23: error: out-of-line definition of 'MyCppNSStringWrapper' does not match any declaration in 'MyCppNSStringWrapper'
MyCppNSStringWrapper::MyCppNSStringWrapper(const char* str)
^~~~~~~~~~~~~~~~~~~~
1.mm:24:1: error: expected expression
����_internal = [[NSString alloc] initWithCString:str
^
1.mm:28:23: error: definition of implicitly declared destructor
MyCppNSStringWrapper::~MyCppNSStringWrapper()
^
1.mm:30:1: error: expected expression
����[_internal release];
^
1.mm:31:1: error: expected expression
����_internal = nil;
^
1.mm:34:36: error: out-of-line definition of 'length' does not match any declaration in 'MyCppNSStringWrapper'
unsigned int MyCppNSStringWrapper::length() const
^~~~~~
1.mm:36:1: error: expected expression
����return [_internal length];
^
1.mm:39:29: error: out-of-line definition of 'characterAtIndex' does not match any declaration in 'MyCppNSStringWrapper'
short MyCppNSStringWrapper::characterAtIndex(unsigned int index) const
^~~~~~~~~~~~~~~~
1.mm:41:1: error: expected expression
����return [_internal characterAtIndex:index];
^
1.mm:44:35: error: out-of-line definition of 'UTF8String' does not match any declaration in 'MyCppNSStringWrapper'
const char* MyCppNSStringWrapper::UTF8String() const
^~~~~~~~~~
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
- with gcc
Code:
gcc42 1.mm -o 1 `gnustep-config --objc-flags` -I/usr/local/lib/gcc42/gcc/x86_64-portbld-freebsd9.0/4.2.5/include
-fconstant-string-class=NSConstantString -I/usr/local/GNUstep/System/Library/Headers
-L/usr/local/GNUstep/System/Library/Libraries -L/usr/local/lib -lgnustep-base
- error
Code:
gcc42: 1.mm: Objective-C++ compiler not installed on this system
Any idea?