How to incorporate C++ code in Objective-C project? -


i'd use c++ code in xcode project don't understand either language enough yet know how proceed. i've been @ obj-c while , have app on app store, still learning...

the code want use has 2 files same name , .h , .c extensions. think correspond .h , .m files in obj-c, lack @interface , @implementation structure i'm familiar with. , there's main.c don't know with. looks it's main program - should try pull code out primary viewcontroller?

maybe link tutorial? maybe question's vague...

fyi - code want use calculating sunrise , sunset times, , located at: http://www.risacher.org/sunwait/

thanks!

edit:

thanks suggestions - have more learning before this. made progress...

in main.c (seems weird have file called that...) there function(?) this:

int mainfunction(int argc, char *argv[]) { // bunch of function-y stuff } 

it called main changed mainfunction rid of error. compiles , can call compiler warns me thus: warning: implicit declaration of function 'mainfunction' , crashes after call it.

first of all, if files have .c extension, c , not c++. have add them project , target , include relevant .h file in objective-c call c functions.

now fact used have function called main() tells had stand alone program. every stand alone program has have function called main(), it's entry point program. objective-c application have function main() why getting error. can take approach of renaming duplicate , calling there number of pitfalls approach.

  • as found out, need function prototype stop implicit declaration warning. should be

    int mainfunction(int argc, char* argv[]); 

    and should in header include in .m file want call it.

  • in c, assumptions made parameters. argc number of char*s in argv. argv[0] conventionally name of program invoked on command line. argc must @ least 1 , argv[0] must point string. remaining char*s in argv point command line parameters.

  • typically, command line program expects able accept input keyboard , display output on screen. done through 3 file descriptors: stdin, stdout , stderr. stdin input, stdout normal output , stderr output of error , other 'out of band' messages. intercepting these file descriptors in gui application non trivial.

i suggest work through basics of c gain understanding of it. can learn enough progress project in day or two. classic text the c programming language. it's still 1 of best imho.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -