Mac Undefined symbols for architecture x86_64

GuidoLicini

macrumors newbie
Original poster
Jun 24, 2014
5
0
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)


Code:
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)
 
Last edited by a moderator:

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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?
You need to add the additional .c file as argument to the compiler, example:

Code:
clang main.c function.c
 

GuidoLicini

macrumors newbie
Original poster
Jun 24, 2014
5
0
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!
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Do you mean importing the .c file in the main.c? This results in the same error.
No. I mean that the .c file needs to be compiled.

Im new to C programming and Xcode, so if you could be a little more specific I would greatly appreciate it!
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.
 

GuidoLicini

macrumors newbie
Original poster
Jun 24, 2014
5
0
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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.
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Yes, the target checkbox is ticked by default, I took a look just now.
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.
 

GuidoLicini

macrumors newbie
Original poster
Jun 24, 2014
5
0
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!
 

neteot

macrumors newbie
Oct 24, 2014
1
0
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
 

briloronmacrumo

macrumors 6502
Jan 25, 2008
474
291
USA
Hi! I am having exactly the same error since my recently installed Yosemite running Xcode 6.1

How did you solve this?

Thank you
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.