Results 1 to 2 of 2
  1. #1

    Member Since
    Jan 14, 2009
    C Program Trouble Compiling w/GCC, Trouble Running in Xcode
    I wrote a C program that worked perfectly in Windows, but I am having trouble using Mac OS. In Windows I used DevC++ to compile and run the program.

    When I tried to compile it in Xcode, it gave me an incorrect output. It kept giving me "inf" and "nan" for what I'm assuming is "infinite" and "not a number." It seems like it's not correctly calculating "eta" on line 121 of my source code (attached).

    I thought it might be a compiler problem so I tried to compile it from the command line using gcc. I used the command:

    gcc SLP.c -o SLP

    It would not compile. This is the error I would get:

    SLP.c:1:19: error: stdio.h: No such file or directory
    SLP.c: In function ‘main’:
    SLP.c:41: warning: incompatible implicit declaration of built-in function ‘printf’

    It seems like there is a problem with my OS recognizing the stdio.h library. I've never had a problem with any C program with Xcode before. I did recently reinstall Xcode with the iPhone SDK. I want to reiterate that my program ran fine with DevC++ on Windows.

    I've attached my code in case anyone wants to look at it. I had to attach it as a text file because a .c file would not upload. Just change the file extension. The correct final outputs should be w(0) = -4, w(1) = 2 and w(2) = 3.
    Attached Files Attached Files

  2. #2

    Member Since
    May 03, 2009
    MBP 2.33 4GB: MacPro 8 Core 2.8, 16GB: MacMini 2.26 4GB: MacMin 2.53 4GB: iPhone3GS 32GB
    I had no issues compiling and running your code via the command line or in XCode so it seems like your environment may be at issue from the CL. Also, you need to declare

    #include <stdlib.h>

    to allow the abs function to be within the compilation scope to get the correct output. If you add this you should be all set.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I'm new to Xcode and I'm having some trouble with finishing my say hello script.
    By raindroprainbow in forum OS X - Development and Darwin
    Replies: 10
    Last Post: 11-25-2012, 05:14 PM
  2. New to programming. Having trouble with Xcode
    By Chris23 in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 11-23-2010, 07:51 PM
  3. Torrent program trouble
    By Yuke14 in forum OS X - Apps and Games
    Replies: 0
    Last Post: 05-13-2007, 02:36 PM
  4. gcc compiling
    By jdgti in forum OS X - Development and Darwin
    Replies: 5
    Last Post: 09-20-2006, 05:08 AM
  5. XCode trouble
    By meskue in forum OS X - Apps and Games
    Replies: 0
    Last Post: 05-19-2006, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts