Thread: C++ in mac pls help.

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    13

    C++ in mac pls help.

    HI..I just learn C++ programming in my college. My college teach us using visual 6c++ , which is a window program. I'm using a macbook right now with Xcode . I'm trying to make C++ using xcode but couldn't built. it gives me this error "Command /usr/bin/gcc-4.0 failed with exit code 1" . So can tell me the solution for this or any other suggested program to do C++ .
    This is just a normal C++ i'm testing with :
    Code:
    #include <stdio.h>
    int main(void)
    {
             printf("Hello!");
             return 0;
    }
    PLS Help ! Thx
    Last edited by Salem; 06-18-2009 at 07:13 AM. Reason: Added [code][/code] tags, learn to use them yourself

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I don't see anything wrong with that code. Did you copy & paste the code you're compiling or did you re-type it?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    I sound like a jerk, but that's not C++, it's C. It still shouldn't cause any issue. What are the build settings on your IDE, or what's being passed into the command line?
    Code:
    #include <cstdio>
    int main()
    {
             std::printf("Hello!");
             return 0;
    }
    Code:
    #include <iostream>
    int main()
    {
          std::cout << "Hello!" << std::endl;
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Registered User
    Join Date
    Mar 2008
    Location
    Coimbra, Portugal
    Posts
    85
    From the looks of it, he might not have GCC installed. More info would definitely help.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Posts
    13
    Well. I'm also not sure whats the problem is. I just downloaded this Xcode3.1 . I just create a project C++ tool then add file C++ file with a.cpp . then i just wrote the program in there. I target the project and run then it will show me that error , if i din target it succeded but it din show me the output. it just says its succeded. Not sure whether that is a target or not, it is a round logo bottom for me to put a tick on it. And what is GCC?
    thank you.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    24
    I'm doing C++ on through xcode 3.1 too at the moment, so I might be able to help. From what I gather gcc is the Gnu C Compiler for C, C++ uses the g++ compiler.

    When you click new project, you select the 'C++ Tool' option from the 'command line utility' template, then it comes up with the same code as you have there, just in C++

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    If you open up a terminal, you can type "gcc --version" or better yet "/usr/bin/gcc-4.0 --version" to see if you have gcc installed or not. I'd try "g++ --version" too.

    But since XCode is trying to execute gcc and not g++, I'd say you're probably trying to compile the code as C. That's probably not a problem, since the code you posted is C and not C++. Just be aware of which language you're learning.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Jun 2009
    Posts
    13
    Well .. i don really understand.. i have another question. when it succeeded why it din show me the output ? how to see the output of my C ? how to execute to show the display like the visual 6 C++ ?
    And to the question above i forget to say that i compile with no error but when i hit built and go then it gave me the error "Command /usr/bin/gcc-4.0 failed with exit code 1" . So whats the matter of this ?
    Last edited by joequah; 06-19-2009 at 12:32 PM.

  9. #9
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    Quote Originally Posted by joequah View Post
    Well .. i don really understand.. i have another question. when it succeeded why it din show me the output ? how to see the output of my C ? how to execute to show the display like the visual 6 C++ ?
    Well, how did you get it to succeed?

    I played with xCode briefly, and everything I did was in GUI's with Cocoa(or whatever it is now). Is there something you have to set to do terminal programs in xCode?

    When I do terminal programs on my Macbook Pro I use TextWrangler as my IDE and just use Terminal and gcc/g++ to compile/run the apps.


    p.s.
    I thought
    Code:
    #include <stdio.h>
    was C++ and
    Code:
    #include "stdio.h"
    was C.

    Never actually tried using < & > in C, always used quotations.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Angle brackets in #includes are C and C++. They mean "look for this header file in the standard places." Double quotes mean "look in the current directory for this header file, and if you don't find it, then look in the standard places." Basically, use angle brackets for built-in header file, and double quotes for your own.

    At a guess: the compile worked, and when you ran it the console window flashed before you were able to see the output. (See the FAQ: Cprogramming.com FAQ > Stop my Windows Console from disappearing everytime I run my program?) "Build" didn't work because you don't have a project, you just have a single source file.

    I'm not sure how good my guess is, but hey, it's a guess.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Registered User
    Join Date
    Feb 2009
    Posts
    37
    XCode does not automatically display the console when the application is executed. What's nice is that XCode logs the output, so the console may be opened after the fact, and you can view output from previous runs.

    To see the output, you'll have to bring up the console, using Command-Shift-R, or select it from the Run menu.
    Command-Alt-R executes the application.
    Last edited by rossipoo; 06-19-2009 at 07:05 PM.

  12. #12
    Registered User
    Join Date
    Jun 2009
    Posts
    13
    ok... i did create a project . the problem now is i can only see the output of the project main.cpp with pressing the command+shift+r but i couldn't run file i create.
    it gives me the error when i put a thick on there.

  13. #13
    Registered User
    Join Date
    Feb 2009
    Posts
    37
    It sounds like you may have two conflicting main() functions in your application.

    If you are adding a new file to the project and defining a main() function in it, then you should have a build error. You can either remove the default main.cpp file from the project or you can simply type your code into the main.cpp file. main.cpp is a good name for a file containing a main function anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mac OS X Users/C programmers?
    By petermichaux in forum C Programming
    Replies: 16
    Last Post: 04-18-2011, 06:36 AM
  2. How to Send Mac Address From Client to Server
    By Lieyza197 in forum C Programming
    Replies: 2
    Last Post: 05-27-2009, 09:58 AM
  3. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  4. mac dvd rom region code
    By lightatdawn in forum Tech Board
    Replies: 3
    Last Post: 03-07-2003, 01:52 PM
  5. help me pls..... :(
    By mocha_frap024 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2002, 10:46 AM