Problem with using gcc , g++ in command line

Discussion in 'Mac Programming' started by Giannos, Sep 15, 2012.

  1. Giannos macrumors newbie

    Joined:
    Sep 15, 2012
    Location:
    Athens,Greece
    #1
    Hi , i am new to the forum , so please dont be hard on me :p

    after a problem i had in my imac and i used the installation dvd of the snow leopard system , when i tried to use gcc , or g++ in the command line of terminal

    Code:
    $ gcc -o factorial.c
    -bash: gcc: command not found
    
    the same thing with g++

    i am not an expert of terminal but here is the thing !!!

    I can use gcc or g++ in xcode or in netbeans but not in the terminal command line !!!

    if i go to usr/bin/ i can see with the ls command g++ and gcc , so the path may be corrupted !!!

    1)Is there a way to unistall gcc and g++ and then reinstall them ?

    2) should i unistall xcode and eveything and reinstall them ?

    3) keep in mind that because i am in university i really need at least one of both running to do my c++ tasks !!!

    thanks in advance !!!!
     
  2. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #2
    You say you see the commands in /usr/bin, have you tried using the full path to call them ? What does the following output when you run them ?

    Code:
    $ /usr/bin/gcc
    $ /usr/bin/g++
    
    Have you checked your PATH environnement variable for /usr/bin ?

    Code:
    $ echo $PATH
    
     
  3. Giannos thread starter macrumors newbie

    Joined:
    Sep 15, 2012
    Location:
    Athens,Greece
    #3
    a friend of mine has fixed some problems for the gcc via remote accesing my mac but there is still one problem only

    Code:
    $ /usr/bin/g++ -o exe bla.cpp
    bla.cpp:1:20: error: iostream: No such file or directory
    bla.cpp: In static member function ‘static void Foo::print()’:
    bla.cpp:12: error: ‘cout’ was not declared in this scope
    bla.cpp:12: error: ‘endl’ was not declared in this scope
    bla.cpp: In function ‘int main()’:
    bla.cpp:31: error: ‘cout’ was not declared in this scope
    bla.cpp:31: error: ‘endl’ was not declared in this scope
    
    
    so it seams now , that the g++ was fixed but there is a problem iwth the librarys :(

    is there a way to just unistall all g++ , gcc , librarys and reinstall them ?

    Code:
    $ echo $PATH
    /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    
    THNX in advance :D
     
  4. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #4
    If you want to know where g++ looks for includes (iostream), type in the following :

    Code:
    $ g++ --print-prog-name=cc1plus
    /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/cc1plus
    $ `g++ --print-prog-name=cc1plus` -v
    ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin11"
    ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/include/c++/4.2.1
     /usr/include/c++/4.2.1/backward
     /usr/local/include
     /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include
     /usr/include
     /System/Library/Frameworks (framework directory)
     /Library/Frameworks (framework directory)
    End of search list.
    ^C
    
    This will tell you what paths llvm is looking into to find the header. For iostream, it should be in the following location by default :

    Code:
    /usr/include/c++/4.2.1/iostream
    What did your friend "fix" ? Please give as much details as possible when posting in a thread so we can help you quickly and without wasting both your and our time.

    Also, what version of Xcode did you install, how did you install the command line tools, etc..
     
  5. Giannos thread starter macrumors newbie

    Joined:
    Sep 15, 2012
    Location:
    Athens,Greece
    #5
    because i am in my second year of computer science , and the friend of mine knew a lot more than me , he tried to help , i didnt understand much of what he did in terminal :(

    i am running xcode version 3.2.5 on snow leopard 10.6.8

    sorry for not being very helpfull :(

    Code:
    Giannos-Vastakis:~ Giannos$ `g++ --print-prog-name=cc1plus` -v
    ignoring nonexistent directory "/usr/include/c++/4.2.1"
    ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10"
    ignoring nonexistent directory "/usr/include/c++/4.2.1/backward"
    ignoring nonexistent directory "/usr/local/include"
    ignoring nonexistent directory "/usr/lib/gcc/i686-apple-darwin10/4.2.1/include"
    ignoring nonexistent directory "/usr/lib/../i686-apple-darwin10/include"
    ignoring nonexistent directory "/usr/include"
    #include "..." search starts here:
    #include <...> search starts here:
     /System/Library/Frameworks (framework directory)
     /Library/Frameworks (framework directory)
    End of search list.
    
    
     
  6. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #6
    Well, the output should have told you what your problem is. You basically don't have the header files installed.

    Code:
    ignoring nonexistent directory "/usr/include/c++/4.2.1"
    How did you reinstall Snow Leopard/Xcode anyhow ? If you used the normal Apple installers, everything should be there.
     
  7. Giannos thread starter macrumors newbie

    Joined:
    Sep 15, 2012
    Location:
    Athens,Greece
    #7
    i followed the instructions from apple support , basically i insterted snow leopard installation dvd , rebooted , hold down the option key and reinstalled the OS X ( not a clean install )

    all my files were intact and all the programms as i left them

    the original problem was solved ( something with the bluetooth )

    but this problem rose

    the xcode wasnt reinstalled , and if i use it i can compile projects , but i cant use g++ and gcc in the command line

    all my .c and .cpp run fine in XCODE as projects :(

    thansk for your help again !!!
     
  8. KnightWRX macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #8
    Well, again, you're missing the contents of /usr/include. It's not that g++ and gcc don't work, they work fine, they just don't have the required standard header files.

    Xcode projects don't use /usr/include, they use <Path to selected SDK>/usr/include, which explains why it works out just fine.

    /usr/include is created when you install Xcode. Just reinstall Xcode (move /Developer to /Developer.old and run the installer again) and everything should be fine.
     
  9. Giannos, Sep 25, 2012
    Last edited: Sep 25, 2012

    Giannos thread starter macrumors newbie

    Joined:
    Sep 15, 2012
    Location:
    Athens,Greece
    #9

    hi , thnx for the tip , i was out of town for a few days !!!! i re download xcode 3.2 for my imac ( snow leopard ) , but i am wondering , cant just i put Xcode in trash can , just by dragging it ?

    also i found
    Code:
    sudo <Xcode>/Library/uninstall-devtools --mode=all
    
    will it work ? thanks in advance !!!




    ////// EDIT : everything fixed , thnx again !!!
     

Share This Page