Xcode C programing help

Discussion in 'Mac Programming' started by pctechtv, Aug 10, 2015.

  1. pctechtv, Aug 10, 2015
    Last edited: Aug 10, 2015

    pctechtv macrumors member

    Joined:
    Sep 3, 2013
    #1
    I have been trying to test some of the code I am working in Visual Studio in Xcode. I am running in to the problem when it comes time to include file in my project. When I use file add files to project, from that point on nothing will build successful. Even more the main.c that Xcode created for me stops working as well (won't build). Could someone suggest what I am not understanding or missing? Thanks

    Screen Shot 2015-08-10 at 10.29.25 PM.png
     
  2. robvas macrumors 68020

    Joined:
    Mar 29, 2009
    Location:
    USA
    #2
    Care to post your error conditions?

    What does main.c look like?
     
  3. cqexbesd macrumors regular

    Joined:
    Jun 4, 2009
    #3
    You don't include the error message you get which makes things difficult but my guess from the picture alone is you still have the auto-generated main function in your project. With the one you added from your source code you now have 2 mains and that isn't allowed. Remove the auto generated main (which I guess is in main.c) and try again.
     
  4. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #4
    Look at your project files pane you'll probably note the existance of a "main.c" in the project template interfering with your successful linking.
     
  5. Senor Cuete macrumors regular

    Joined:
    Nov 9, 2011
    #5
    MY wild guess is that func() is defined in both main.c and func.c.
     
  6. pctechtv thread starter macrumors member

    Joined:
    Sep 3, 2013
    #6
    Thanks guys a great help, it is what all of you suggest. Forgive me for lack of understanding of terminology in Xcode and how to work with C constructs. I started with programing with JavaScript and PHP this C stuff is new to me. The suggestions you guys said already helped me understand better. As for the project files pane (lloyddean suggest) I never found it. I do think that is the problem “successful linking” once deleting all other files with a main function it worked fine. I am including a pic of the error message here, it also says something about linking. I would like to know why if any of you know…. why Visual Studio does not have the same problem?

    xcodeHelp1.jpg
     
  7. pctechtv thread starter macrumors member

    Joined:
    Sep 3, 2013
    #7
    I am wrong guys, Visual Studio does give the same error when the files are in same location. I was missing it, the way I was running them following lessons. Disregard my question about Visual Studio. So a C program can only have one main function.... good to know! As for not being able to find the "project files pane" I am still searching, I am using Xcode 7 beta. Could this be why I don't find it? Thanks
     
  8. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #8
    Perhaps it's the one in the image you included that contains the files "func.c", "func.h", "working.c" and "main.c"?

    You show us the content of the "func.c" which clearly contains your "main" function but failed to remove the file "main.c" from the project meaning the linker is likely complaining of more than one main function in the project.
     
  9. pctechtv, Aug 12, 2015
    Last edited by a moderator: Aug 12, 2015

    pctechtv thread starter macrumors member

    Joined:
    Sep 3, 2013
    #9
    I get it, I was looking at it! I thought that is was a specific other view. Thank you so much, you and the other members helped a great deal. I am working now, and cam continue learning more. Thanks!!!
     

Share This Page