开发者

Convert C function to Objective C or alternative way to include C library?

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 f开发者_StackOverflow社区ound 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!


You don't import implementation files. You just compile them alongside and include the appropriate header so that your code knows about the function and datatype declarations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜