0

First of all, Happy New Year to anybody out there reading this!

I have an i-phone app I am working on and wanted to make an enhancement to an IBACTION (GetNextElement) which is called from a button tap. I wanted to call a function (get_index_to_use) rather than insert the code in GetNextElement. When I call the function in my SymbolTest.m file, I get a warning "implicit declaration of function get_index_to_use".

I get an error on the build that I don't see unless I go into Build Results where I see the following:

Ld build/Debug-iphonesimulator/elements1.app/elements1 normal i386 cd /Users/dad/Documents/elements1 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/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk -L/Users/dad/Documents/elements1/build/Debug-iphonesimulator -F/Users/dad/Documents/elements1/build/Debug-iphonesimulator -filelist /Users/dad/Documents/elements1/build/elements1.build/Debug-iphonesimulator/elements1.build/Objects-normal/i386/elements1.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -o /Users/dad/Documents/elements1/build/Debug-iphonesimulator/elements1.app/elements1

Undefined symbols: "_get_index_to_use", referenced from: -[SymbolTest GetNextElement:] in SymbolTest.o ld: symbol(s) not found collect2: ld returned 1 exit status

I'm not familiar with SymbolTest.o.

I have my function in the code before GetNextElement. I tried to put it in SymbolTest.h. I tried to put it in GetNextElement but couldn't get that to work either. I have tried - and +. The function looks like this (eventually I want to change how I calculate the index, but for now I am just incrementing it to get the function to work):

- (void)get_index_to_use {
    el_tbl_idx++;
}   

Any help would be appreciated. Thanks.

3
  • please post some code, i.e. the action and the declaration of get_index_to_use... Commented Jan 1, 2012 at 15:33
  • SymbolTest.o is the object file generated by the compiler, probably from SymbolTest.m (though possibly .mm or c or cpp) Commented Jan 1, 2012 at 15:34
  • Right now the get_index_to_use is a one-liner until I can get it working: - (void)get_index_to_use { el_tbl_idx++; } It's called in an else statement: else { get_index_to_use(); SymbolEntered.text = nil; ElementName.text = [NSString stringWithCString:elements_table2[el_tbl_idx].element_name]; }; Don't know why this post isn't formatting on the display. It looks nice in this window I am typing in but when I post it all runs together. Commented Jan 1, 2012 at 15:40

1 Answer 1

2

here is your problem, you have declared a method and then tried to call like a C function.

you will want to use (C style function)...

void get_index_to_use (void)
{ el_tbl_idx++; }

then call with:

get_index_to_use()

or

- (void) get_index_to_use
{el_tbl_idx++; }

and call with:

[self get_index_to_use];

or more generically:

[someObject get_index_to_use];

but it is generally a good idea to stick to naming conventions, one of which, is if you method starts with get, it should be a getter and return something. The following looks more Obj-C.

-(NSUInteger)getIndex {
     el_tbl_idx+=1; // or ++ or = x+1;
     return el_tbl_idx; 
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much. I will give that a try. This is my first i-phone app and I'm trying to take a c program I wrote and get it to work as an i=phone app and sometimes confuse the two. I will try to follow the Obj-C approach. Thanks again, and Happy New Year.
one thing to note... all C is valid in Objective-C.. no need to reinvent the wheel... the only thing you will really have to remember is that any objects iVars are only available in the objects (instance) methods. Calling a C function is a little bit faster than calling a method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.