开发者

Xcode not recognizing file

I added two files (takeoff.h, takeoff.c) to my Xcode project including pasting some code from another project. Now after a successful compile, Xcode doesn't see开发者_高级运维m to recognize the new files. A call from main.c is just ignored even though everything compiles fine. What's going on and how do I fix it?

 // main.c
 int main()
 {
     void test(void); // located in takeoff.c JUST IGNORED
 }

 //takeoff.c
 void test(void)
 {
     print("Printed from takeoff.c");  // no printing nor do breakpoints stop her
 {


Change to:

 // main.c

 void test(void); // <--- NB: function *prototype*

 int main()
 {
    test();  // <--- NB: function *call*
 }

and:

 // takeoff.c

 #include <stdio.h> // <--- NB: missing #include for printf

 void test(void)
 {
     printf("Printed from takeoff.c\n"); // <--- NB: *printf*, not *print*
 } // <--- NB: fixed closing brace

(Corrections are marked with <---)


It's not a valid function call, just a function declaration.

 void test(void); // function declaration 

Change it to test();


Make sure the .c is added to the target. In xcode 4, it's ALT-CMD-1. On the right in "Target Memberships" make sure your active target is checked. Otherwise, everything will look like it's compiling, but it won't actually be running anything.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜