can i write in c, c++ then compile with xcode and run in iphone?

Member
Posts: 164
Joined: 2010.10
Post: #1
i'm a neewbie.
i have a mac, downloded xcode.
i would like to make an iphone game and use code written in c, c++.
can i use the code written in c, c++ or the game will launch only in jailbroken iphone?
thanks
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Yes. Though you will need at least a little Objective-C code to set up a drawing context and receive events.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #3
the game will launch only in jailbroken iphone?
i'd like to find a library of 3d physics, i have found
http://www.impulse-based.de/index.php?op...&Itemid=16
written in c++, i was wondering if i can use it...
or there is someone in objective-c?
thanks for the very quik answer!!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
No, you can use pretty much whatever language you want on the iPhone. The official tools come with a C, C++, and Objective-C compilers.

For 3D physics, Bullet is probably your best bet. Unity3D has a nice physics engine built in as well, but is not free.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #5
many thanks i have downloaded it, now i try
thanks a lot!
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #6
hi again, i have much problem...
i have downloaded bullet and cmake. (i have tried to do something with cmake but nothing, must retry)
however i think that i can compile all without cmake but using xcode right?
so i have:
1) started a new openglES application in xcode
2) on project->edit project settings i have setted header search path to Add the bullet-2.77/src folder
3) #import "btBulletDynamicsCommon.h" in main.m
4) compiled...many and many error occour

i have readed that i must change properties using Info button in the toolbar, go to the General tab and find the File Type dropdown
Change the filetype from sourcecode.c.objc to sourcecode.cpp.objcpp

but two error appears:

Ld build/Debug-iphonesimulator/provaphys1.app/provaphys1 normal i386
cd /Users/sefi/Documents/provaphys1
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -L/Users/sefi/Documents/provaphys1/build/Debug-iphonesimulator -L/Users/sefi/Documents/provaphys1/bullet-2.77/Glut -F/Users/sefi/Documents/provaphys1/build/Debug-iphonesimulator -filelist /Users/sefi/Documents/provaphys1/build/provaphys1.build/Debug-iphonesimulator/provaphys1.build/Objects-normal/i386/provaphys1.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -o /Users/sefi/Documents/provaphys1/build/Debug-iphonesimulator/provaphys1.app/provaphys1

Undefined symbols:
"btAlignedFreeInternal(void*)", referenced from:
btAlignedAllocator<btHashInt, 16u>::deallocate(btHashInt*) in main.o
btAlignedAllocator<btTriangleInfo, 16u>::deallocate(btTriangleInfo*)in main.o
btAlignedAllocator<int, 16u>::deallocate(int*) in main.o
"btTypedConstraint::serialize(void*, btSerializer*) const", referenced from:
vtable for btTypedConstraintin main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

can somone help me please?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #7
Sounds like you've included bullet headers without actually linking to the bullet library. In general, header files define an API at compile time, but don't provide an implementation; the corresponding library (.a) file contains the implementation which is needed at link time. You need to add libbullet.a (or whatever it's called) to the libraries linked in your project.
Quote this message in a reply
Member
Posts: 27
Joined: 2009.07
Post: #8
Not to be rude, but it seems like you don't have much experience working with C++. if you're planning on doing development for iOS devices (iPhone/iTouch/iPad) and don't have a high level of experience with C++, I'd recommend instead looking into learning Objective-C. After you're comfortable with Obj-C, you can start learning the basics of C++ and integrating projects that use it through the use of Objective-C++.

Goodbye.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #9
hi, is the first time i use xcode and a mac.
i have follower this instructions to compile bullet:
cd path/to/bullet
mkdir bullet-build
cd bullet-build
cmake .. -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON -DFRAMEWORK=ON \
-DCMAKE_OSX_ARCHITECTURES='i386;x86_64' -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=/Library/Frameworks -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks \
-DBUILD_DEMOS:BOOL=OFF
make -j4
sudo make install

ask for a password. when i have installed snowleopard in the profile i have choosed not to have a password, but if i click <enter> says wrong password...
with cmake from gui i have compiled all as an xcode project, and all went well.
i have found that extension of the library is .a so i added statically the library and goes well. thanks
however...how can i solve the password error so i can have the framework?
thanks
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #10
I seem to recall sudo not accepting zero-length passwords, though I could be completely wrong about that. If that's the case, though, you can simply change your user password to something that's not blank, which isn't exactly a bad idea for security anyway.

Installing libraries you're compiling against is generally inadvisable. There's a potential annoyance and a potential danger to this: the annoyance is that you increase the overhead required to build your application on any computer other than your own by making it necessary to install the library first, and the danger is that you inadvertently link to the library in such a way that it requires end users to install it to run your application. Both of these things can be prevented by keeping the library in your project directory and never installing it (as well as being mindful of how you link to it).
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #11
ok many thanks for advices, so adding library statically as i have done is the best thing if i have understood well...
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #12
Also - If you are targeting the iphone, you definitely don't want to build your target using the build settings of 'i386;x86_64' you listed earlier....
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  (Relatively) easy way to compile XCode projects in MinGW on Windows? Justin Brimm 10 10,132 May 16, 2008 05:37 AM
Last Post: ThemsAllTook
  How to write a custom memory manager Malarkey 3 3,626 Oct 27, 2005 09:52 AM
Last Post: aqua_scummm