Undefined symbols for architecture x86_64

Discussion in 'Mac Programming' started by GuidoLicini, Jun 24, 2014.

  1. GuidoLicini, Jun 24, 2014
    Last edited by a moderator: Jun 25, 2014

    GuidoLicini macrumors newbie

    Jun 24, 2014
    I am having an error when trying to use a function I created (in .h and .c files) in the main.c file. I've imported the .h file containing the function which is also imported in its respective .c file.

    Any ideas on how to solve this?

    Thanks in advance!

    (pasting the error below)

    Ld /Users/Guido/Library/Developer/Xcode/DerivedData/Proyecto2.3-ertriwqybmccuobtvwpypjxnriku/Build/Products/Debug/Proyecto2.3 normal x86_64
        cd /Users/Guido/Documents/C/Proyecto2.3
        export MACOSX_DEPLOYMENT_TARGET=10.9
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/Guido/Library/Developer/Xcode/DerivedData/Proyecto2.3-ertriwqybmccuobtvwpypjxnriku/Build/Products/Debug -F/Users/Guido/Library/Developer/Xcode/DerivedData/Proyecto2.3-ertriwqybmccuobtvwpypjxnriku/Build/Products/Debug -filelist /Users/Guido/Library/Developer/Xcode/DerivedData/Proyecto2.3-ertriwqybmccuobtvwpypjxnriku/Build/Intermediates/Proyecto2.3.build/Debug/Proyecto2.3.build/Objects-normal/x86_64/Proyecto2.3.LinkFileList -mmacosx-version-min=10.9 -Xlinker -dependency_info -Xlinker /Users/Guido/Library/Developer/Xcode/DerivedData/Proyecto2.3-ertriwqybmccuobtvwpypjxnriku/Build/Intermediates/Proyecto2.3.build/Debug/Proyecto2.3.build/Objects-normal/x86_64/Proyecto2.3_dependency_info.dat -o /Users/Guido/Library/Developer/Xcode/DerivedData/Proyecto2.3-ertriwqybmccuobtvwpypjxnriku/Build/Products/Debug/Proyecto2.3
    Undefined symbols for architecture x86_64:
      "_listaenarreglo", referenced from:
          _main in main.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
  2. subsonix macrumors 68040

    Feb 2, 2008
    You need to add the additional .c file as argument to the compiler, example:

    clang main.c function.c
  3. GuidoLicini thread starter macrumors newbie

    Jun 24, 2014
    Do you mean importing the .c file in the main.c? This results in the same error.

    Im new to C programming and Xcode, so if you could be a little more specific I would greatly appreciate it!

    Thank you for helping!
  4. subsonix macrumors 68040

    Feb 2, 2008
    No. I mean that the .c file needs to be compiled.

    You did not say that you were using Xcode, and now you ask me to be specific. The comment is very specific but it assumes you are compiling it manually.

    Is the project a C command line tool? How did you add the files to the project? If you add a new .c file to the project you automatically get a .h file, there is also a check box for the project target which is set by default, which means that the compile knows about the new .c file.
  5. GuidoLicini thread starter macrumors newbie

    Jun 24, 2014
    Yes, the project is indeed a C command line tool. I added the files with the File->Add New->File (this is for all the files in the project) and started from scratch.
  6. subsonix macrumors 68040

    Feb 2, 2008
    And did you check that the target checkbox was ticked. If you add a new C file it should automatically be set. If you look at build phases, under compile sources then you should see all C files there, including the one with the missing symbol. If not, try to add it there.
  7. GuidoLicini thread starter macrumors newbie

    Jun 24, 2014
    Yes, the target checkbox is ticked by default, I took a look just now.
  8. subsonix macrumors 68040

    Feb 2, 2008
    Did you check that you spelled the function "listaenarreglo" in the header file, the C file and in main the same? If not, you will get the same error because the function with that name does not exist. If that's not it, I don't know, perhaps someone else can help you.
  9. GuidoLicini thread starter macrumors newbie

    Jun 24, 2014
    Yup, the function is spelled correctly in all three files. I tried the code in code blocks in a pc and it did not have this error. I guess its not really a solution but got the job done.

    Thank you very much for your help subsonix!
  10. neteot macrumors newbie

    Oct 24, 2014
    Did you solve this?

    Hi! I am having exactly the same error since my recently installed Yosemite running Xcode 6.1

    How did you solve this?

    Thank you
  11. briloronmacrumo macrumors 6502


    Jan 25, 2008
    This is a coding and/or usage error by the programmer and isn't an Xcode error. It is not caused by the operating system or by Xcode, so Yosemite and Xcode can't be blamed. Usually the programmer hasn't observed case-sensitivity or something wasn't added to the target.

    The error is issued by the linker (ld) because it can't resolve a reference to a symbol.

    Suggest googling "ld: symbol(s) not found for architecture" and look at some of the stackoverlfow threads.

Share This Page