Ubiquitous "Undefined symbols for architecture x86_64" Error

Discussion in 'Mac Programming' started by gravity black, Dec 8, 2011.

  1. gravity black, Dec 8, 2011
    Last edited: Dec 8, 2011

    macrumors newbie

    Joined:
    Oct 18, 2011
    #1
    Hi all,

    I'm trying to program a graph class using an adjacent list from an example in my C++ text book, and when I compile using this command:
    Code:
    g++ -o prog program.cpp
    
    ...I get the following error:

    Code:
    Undefined symbols for architecture x86_64:
      "_main", referenced from:
          start in crt1.10.6.o
    ld: symbol(s) not found for architecture x86_64
    collect2: ld returned 1 exit status
    
    ... what in the world does this mean? It may turn out to be an issue with my code, but I feel like it may be deeper than that, because I've gotten this same seemingly inexplicable error for several different projects, many of which were solved in different ways, and unfortunately completely by accident.

    I read somewhere that it may have to do with whether I'm using 32 bit or 64 bit libraries, and that the tags -m32 or -m64 may need to be used, but I'm not sure if this applies here.

    Mainly I just want to know what in the world the error is saying. I'm used to debugging compile-time errors that give a specific line in the code, etc., but I can't discern anything like that from this. Any ideas?

    If it helps, I'm using a late 2008 Macbook with Intel Core 2 Duo, (so 64-bit), and I'm running OS X Lion (10.7.2), which I think is the latest version. Also, I'm using gcc version 4.2.1.
     
  2. macrumors 6502a

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    Does your program have a main() function in it? Is this program small? Can you post it?

    Can you re-produce this error with a HelloWorld program? That might indicate whether your XCode install is messed up somehow.
     
  3. thread starter macrumors newbie

    Joined:
    Oct 18, 2011
    #3
    Ah, what a simple mistake. No, I did not have a main() function. Thanks for the help.
     
  4. macrumors newbie

    Joined:
    Aug 15, 2012
    #4
    Hey!

    So actually what was your problem? I get same errors.
     
  5. macrumors newbie

    Joined:
    Apr 18, 2008
    #5
    He already stated what the problem was. He did not have a main() function. A C++ program has to start somewhere, and it always starts by calling main(). So you have to provide a main() function in order for your program to run.
     

Share This Page