Convert C function to Objective C or alternative way to include C library?
Posted
by Moshe
on Stack Overflow
See other posts from Stack Overflow
or by Moshe
Published on 2010-03-28T05:58:29Z
Indexed on
2010/03/28
6:03 UTC
Read the original article
Hit count: 240
Background:
I'm new to Objective-C and I've never touched C before. I'm trying to include a C library in my iPhone/iPod Touch project and I could not successfully compile the library's source code using the included instructions, so I've resorted to including the .h and .c files in Xcode. The library is for Hebrew Dates and corresponding Jewish Holidays. It can be found here: http://sourceforge.net/projects/libhdate/
I cannot seem to import the .c files into my implementation files. I can import the .h files though. When I try to use #import "file.c"
, where file.c is a file that is in XCode, it doesn't work. Why not?
I've considered just writing the functions over in Objective-C, albeit only my needed functions and not the whole library.
How can I make the following C function work in Objective-C? Are there other things that need to be included/re-coded/compiled? How so? I am almost certain something is missing, but I'm not sure what.
Code:
int hdate_get_omer_day(hdate_struct const * h)
{
int omer_day;
hdate_struct sixteen_nissan;
hdate_set_hdate(&sixteen_nissan, 16, 7, h->hd_year);
omer_day = h->hd_jd - sixteen_nissan.hd_jd + 1;
if ((omer_day > 49) || (omer_day < 0))
omer_day = 0;
return omer_day;
}
So... should I be converting it, or trying somehow to compile to an appropriate format and how so? (I don't know what format a static library should be in, by the way, or if it should be static... - I'm so lost here....)
I appreciate the help!
© Stack Overflow or respective owner