hrrrr,I have fixed the problem.
Some suggestions are as following:
1\ change all *.m files ext to *.mm
2\put your c++ code in *.cpp files
3\change your makefile .
Code:
CC=arm-apple-darwin-gcc
CXX=arm-apple-darwin-g++
LD=$(CXX)
LDFLAGS=-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit
LDFLAGS+=-L/usr/local/lib -lz -lstdc++
CFLAGS=-Wall -O2
CFLAGS += -I/usr/local/include
all: hello
hello: Hello.o HelloApplication.o hello1.o
$(LD) $(LDFLAGS) -o $@ $^
%.o: %.mm
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o: %.cpp
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
clean:
rm -f *.o hello
4\in *.mm files ,you can new a class.
hmmmm,if you still have questions,please send email to me.[pchard AT 126 DOT com].
I have another questions:
How to user BSD socket in iPhone?
The following code is not work:
Code:
NSString* hostName = [[NSString alloc] initWithString:@"www.google.com"];
unsigned short port = 80;
struct hostent* remoteHost;
struct sockaddr_in remoteAddr;
// Socket must be created, and not already connected
if ( (socketfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
[NSException raise:SOCKET_EX_CANT_CREATE_SOCKET
format:SOCKET_EX_CANT_CREATE_SOCKET_F, strerror(errno)];
if ( socketfd == SOCKET_INVALID_DESCRIPTOR )
[NSException raise:SOCKET_EX_BAD_SOCKET_DESCRIPTOR
format:SOCKET_EX_BAD_SOCKET_DESCRIPTOR];
connected=NO;
if ( connected )
[NSException raise:SOCKET_EX_ALREADY_CONNECTED
format:SOCKET_EX_ALREADY_CONNECTED];
// Look up host
[COLOR="Red"]if ( (remoteHost = gethostbyname([hostName cString])) == NULL ) return NULL,WHY?
[/COLOR]