Iphone, calling C function from a .mm file

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Iphone, calling C function from a .mm file

Postby Julio Jerez » Mon Jul 27, 2009 1:32 pm

I am making the iNewton Class and I am having a huge problem with .m and .mm class in objective C
Basically I do not know how to call function from a .mm class to a C funtion defined in a .m file
here in my .m vector file
Code: Select all
struct dVector
{
   float m_x;
   float m_y;
   float m_z;
   float m_w;
};

struct dVector InitVector (float x, float y, float z, float w);
struct dVector Scale (struct dVector* me, float s);
struct dVector AddVector (struct dVector* A, struct dVector* B);
struct dVector SubVector (struct dVector* A, struct dVector* B);
...



here is my .mm iNewtion class

Code: Select all
#import <Foundation/Foundation.h>

@class Entity;
@interface iNewton : NSObject
{
   void* m_world;
}

-(id) init;
-(void) dealloc;
-(void*) CreateBox: (Entity*) ent: (int) shapeId;
...
@end


I can not call any Vector function or other function from the .mm class, here is tthe implementatin of CreateBox in a .mm file
Code: Select all
-(void*) CreateBox: (Entity*) ent: (int) shapeId
{
          struct dVector minBox;
          struct dVector maxBox;
           // this is fine, because it is a class member on Entityr
           [ent GetBBox: &minBox: &maxBox];
   
          // this reports a link error, because ther are C funtion in a .m file
          struct dVector size = SubVector(&maxBox, &minBox);
          struct dVector origin = AddVector (&maxBox, &minBox);
          ...
           return NewtonCreateBox ((NewtonWorld*) world, size.m_x, size.m_y, size.m_z, shapeId, &offset.m_front.m_x);
}



I get these complier errors
Building target “tutorial_102_AddingRigidBody” of project “newton_iPhone” with configuration “Debug_Emulation” — (3 errors)
cd /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone
setenv MACOSX_DEPLOYMENT_TARGET 10.5
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.0 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk -L/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator -L/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/../sdk -F/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator -filelist /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator/tutorial_102_AddingRigidBody.build/Objects-normal/i386/tutorial_102_AddingRigidBodies.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -framework CoreGraphics -lnewton_iPhoneEmulation -o /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator/tutorial_102_AddingRigidBodies.app/tutorial_102_AddingRigidBodies
Undefined symbols:
"AddVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"SubVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"Scale(dVector*, float)", referenced from:
-[iNewton CreateBox::] in iNewton.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
"AddVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"SubVector(dVector*, dVector*)", referenced from:
-[iNewton CreateBox::] in iNewton.o
"Scale(dVector*, float)", referenced from:
-[iNewton CreateBox::] in iNewton.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build failed (3 errors)

does anyone knows what I need to do to solve this problem, I am trying since yesterday but I can not figure out what to do.
Ther must be a way to do that, teh docimenation in objective C say teh .m file can have class and C files.
why I can not call C funtions from and .mm file them?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Iphone, calling C function from a .mm file

Postby winstrol » Mon Jul 27, 2009 9:16 pm

Hi,

I am not Kevin Mitnick, and I am new in Xcode and obj-c, but:
1> I always put headers into *.h file, and methods into *.m

2> syntax like
void* m_world;
looks strange for me. What type you want for that variable?

3> in: -(void*) CreateBox: (Entity*) ent: (int) shapeId;
-(void*) CreateBox: (Entity*)<here should be name of variable, like shapeId in next int> ent: (int) shapeId;
and another (void*) ? hmm
if you want to return instance of class NewtonBox you should write:
-(NewtonBox *)CreateBox:(Entity *)ent andShape:(int)shapeId; - I think you wanted something like this


4> Compiled errors like: -[iNewton CreateBox::]
suggest that you are trying to put c++ syntax into obj-c libs


I recomend first few lectures from
http://www.stanford.edu/class/cs193p/cgi-bin/index.php
if you want code obj-c

Send me your project if you can on stage you have, maybe I will solve something

regards
Andrew
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Iphone, calling C function from a .mm file

Postby Julio Jerez » Mon Jul 27, 2009 9:38 pm

What I am doing is correct,
the problem happen with this line

struct dVector size = SubVector(&maxBox, &minBox);
struct dVector origin = AddVector (&maxBox, &minBox);

wich apparetly cannot be called from a .mm files
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Iphone, calling C function from a .mm file

Postby Julio Jerez » Mon Jul 27, 2009 10:36 pm

here is the project, maybe this will make more clear.
http://www.newtondynamics.com/downloads/NewtonSDK.zip
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Iphone, calling C function from a .mm file

Postby winstrol » Tue Jul 28, 2009 8:43 am

Hmm,

I don't know why, but I have also problem:

Checking Dependencies
Processing /Users/xxx/Downloads/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator/tutorial_101_GettingStarted.app/Info.plist /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/tutorial_101_GettingStarted-info.plist
cd /Users/xxx/Downloads/NewtonSDK/newton_iPhone
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
<com.apple.tools.info-plist-utility> /Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/tutorial_101_GettingStarted-info.plist -genpkginfo /Users/xxx/Downloads/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator/tutorial_101_GettingStarted.app/PkgInfo -expandbuildsettings -format binary -o /Users/xxx/Downloads/NewtonSDK/newton_iPhone/build/Debug_Emulation-iphonesimulator/tutorial_101_GettingStarted.app/Info.plist
error: The file “tutorial_101_GettingStarted-info.plist” does not exist.
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm

Re: Iphone, calling C function from a .mm file

Postby Julio Jerez » Tue Jul 28, 2009 9:26 am

You need to build Tutorial_102_adding RidigBies, to see the problem
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Iphone, calling C function from a .mm file

Postby Julio Jerez » Tue Jul 28, 2009 10:55 am

Ok I found a work aroudn solution.
Maybe now I can complete the Iphone demos, cross my fingers nock in the wood.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Iphone, calling C function from a .mm file

Postby winstrol » Tue Jul 28, 2009 11:18 am

In Project>Edit active target I had to change value of Packaging/Info.plist File from:
/Users/juliojerez/Desktop/NewtonMac/NewtonSDK/newton_iPhone/tutorial_101_GettingStarted-info.plist
to my directory

so, if you want do project working out of the box I recommend you to use syntax like:
$(SRCROOT)/tutorial_101_GettingStarted-info.plist
in that place

about your problem, can you write your solution for executing c functions in *.mm ?
User avatar
winstrol
 
Posts: 30
Joined: Fri Jul 24, 2009 9:57 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest