Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

krautrockblog

macrumors newbie
Original poster
Jan 20, 2008
1
0
i try to build a iphone game by porting from the existing c++ game source code. but the trouble is that i cannot new a std c++ class. note that i have installed the recent iphone toolchain and can compile doom source code etc correctly,the doom sample source is c, not c++. (i can build a helloworld as well,which is object c).
i have tried with apple-darwin-gcc or apple-darwin-g++.always failed.
anybody knew how to handle with this trouble?
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
Is this the unofficial SDK that's floating about?

This might be a stupid question, but are you sure it supports C++? The only samples I've seen are Obj-C.
 

coolhome

macrumors newbie
Jan 29, 2008
2
0
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]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.