Results 1 to 14 of 14
  1. #1


    Member Since
    Jan 31, 2009
    Posts
    49
    How To Compile .cpp Files On Mac
    I downloaded g++ and put

    Code:
    g++ password.cpp -o RandomPswrd
    ^ this in the termional but I get a bash error. The .cpp is in the gcc-4.40 folder. I just dragged the password.cpp into the folder. How can I compile these files?

  2. #2

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    do you get a specific bash error?
    mike
    This machine kills fascists
    Got # ? phear the command line!

  3. #3


    Member Since
    Jan 31, 2009
    Posts
    49
    -bash: g++: command not found

    ???

    That's after I put in the code the RandomPswrd can be anything right?

  4. #4


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    That error usually shows up if either:

    1) The path to the executable is not in the exported path
    2) The software hasn't been installed.

    Just out of curiosity, have you installed g++, or the xcode developer pack? AFAIK, installing OSX by itself doesn't install the compilers. I think a version of XCode may be on the OSX disc that you can install, but you might as well get the most current version from apple and register as a developer. It's free and once properly installed, you should have no problems.
    My Macs: Late 2013 rMBP w/ 750m, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Linux; Apple TV (1080p version)

  5. #5

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    GCC/G++ has to be compiled (the irony).

    Download the developer tools from the Apple developer site or install Xcode/dev tools from your OS X installation disc to get an installed binary of GCC. Your best bet is to get it from the Apple dev site though as Xcode will be a newer version there.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  6. #6


    Member Since
    Jan 31, 2009
    Posts
    49
    bump

    I downloaded xcode but now I get

    i686-apple-darwin9-g++-4.0.1: password.cpp: No such file or directory
    i686-apple-darwin9-g++-4.0.1: no input files

  7. #7

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    so is password.cpp in the directory you're running the compile from?
    mike
    This machine kills fascists
    Got # ? phear the command line!

  8. #8


    Member Since
    Jan 31, 2009
    Posts
    49
    What do you mean? It is in a gcc-4.40 folder.

  9. #9

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    you have to be in the directory your source is in to compile it.

    So, for instance.. if your password.cpp was in your home directory under a folder called source.. you'd have to

    cd ~/source
    g++ password.cpp -o RandomPasswd

    for it to compile. Or, you'd have to specify the path to the source like

    g++ /path/to/password.cpp -o RandomPasswd

    It can't guess where your source is.
    mike
    This machine kills fascists
    Got # ? phear the command line!

  10. #10


    Member Since
    Jan 31, 2009
    Posts
    49
    Ok, so I put a folder called source in finder > steven (right below "desktop") and inside the source folder is the password.cpp and now I get this:

    password.cpp: In function ‘int main()’:
    password.cpp:8: error: ‘srand’ was not declared in this scope
    password.cpp:18: error: ‘rand’ was not declared in this scope

  11. #11

    Dysfunction's Avatar
    Member Since
    Mar 17, 2008
    Location
    Tucson, AZ
    Posts
    6,866
    Specs:
    Way... way too many specs to list.
    Now you have programatic errors

    Try gdb password.cpp
    mike
    This machine kills fascists
    Got # ? phear the command line!

  12. #12


    Member Since
    Feb 25, 2009
    Posts
    2,112
    Specs:
    Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
    I'll give you a hint - you're missing an include file
    My Macs: Late 2013 rMBP w/ 750m, 16Gig ram; 2013 Mac Pro 6 core w/ D700, 16Gig Ram; Mac mini G4, 1.25 GHz, 512m ram (server); Late 2011 11" MBA, 1.8GHz i7, 4Gig Ram, 256Gig SSD, HD3000; Powerbook 12" G4 1.33GHz running Linux; Apple TV (1080p version)

  13. #13


    Member Since
    Jan 31, 2009
    Posts
    49
    what include file?

  14. #14

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Read here and here - those may help.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How do I compile DNSCrypt for Mac
    By jewfromdahood in forum OS X - Apps and Games
    Replies: 4
    Last Post: 02-18-2014, 12:55 PM
  2. How to compile (without building) a .c/.cpp file with Xcode?
    By ZhimingWang in forum OS X - Development and Darwin
    Replies: 7
    Last Post: 08-27-2013, 10:46 AM
  3. How do I compile source code on a mac Im trying to compile hydra 7.1.src.tar.gz on a
    By programmaster in forum OS X - Development and Darwin
    Replies: 5
    Last Post: 11-15-2011, 10:16 AM
  4. could some one compile something for me
    By heavensent in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 07-06-2007, 03:55 AM

Posting Permissions

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