g++ error

Discussion in 'Mac Programming' started by aaeyers, Feb 16, 2008.

  1. macrumors newbie

    Joined:
    Feb 16, 2008
    #1
    I've been trying to compile a test c++ program (test.cpp) in the terminal, but I can't get g++ to run. I keep getting an error, and I have no idea what it means, could any of you guys help me out?

    Code:
    x-134-84-96-216:~ aaeyers$ g++ test.cpp -o test
    /usr/bin/ld: /usr/lib/gcc/i686-apple-darwin8/4.0.1/libstdc++.dylib load command 5 unknown cmd field
    /usr/bin/ld: /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libSystem.dylib unknown flags (type) of section 6 (__TEXT,__literal16) in load command 0
    /usr/bin/ld: /usr/lib/libSystem.B.dylib unknown flags (type) of section 6 (__TEXT,__literal16) in load command 0
    collect2: ld returned 1 exit status
    x-134-84-96-216:~ aaeyers$ 
    
     
  2. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #2
    Can you post your code?
     
  3. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #3
    To my test program?

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
      int num;
      cout <<"Enter number: ";
      cin >> num;
      cout << endl << "Your number is " << num << endl;
      return(0);
    }
     
  4. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #4
    Ok, I reinstalled the developer tools, and now I can compile files, but they won't run in the terminal. Using the same program, I compile it, and try running it, but nothing happens. I've tried running a bunch of programs that I've written (that work when I compile and run in Ubuntu), but none of them seem to be recognized in the terminal.

    Code:
    x-134-84-96-216:~ aaeyers$ cd  Projects
    x-134-84-96-216:Projects aaeyers$ ls
    csci1113	test		test.cpp	test.cpp~
    x-134-84-96-216:Projects aaeyers$ emacs test.cpp
    x-134-84-96-216:Projects aaeyers$ g++ test.cpp -o test
    x-134-84-96-216:Projects aaeyers$ test
    x-134-84-96-216:Projects aaeyers$ 
    
    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
      int num;
      cout <<"Enter number: ";
      cin >> num;
      cout << endl << "Your number is " << num << endl;
      return(0);
    }
     
  5. macrumors 6502

    Joined:
    Jun 16, 2004
    #5
    Your program isn't running because you are trying to execute the 'test' program thats in the path (/bin/test) as opposed to your program. Try using './test' (minus quotes)
     
  6. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #6
    Oh alright, got it. Thanks for the help. I never would have figured that out on my own.
     
  7. macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #7
    Read the man page for the 'which' command. :)
     

Share This Page