-1
Ld /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug/c normal x86_64
cd /Users/ashutoshagarwal/Desktop/c
setenv 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/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug -F/Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug -filelist /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Intermediates/c.build/Debug/c.build/Objects-normal/x86_64/c.LinkFileList -mmacosx-version-min=10.9 -framework Foundation -Xlinker -dependency_info -Xlinker /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Intermediates/c.build/Debug/c.build/Objects-normal/x86_64/c_dependency_info.dat -o /Users/ashutoshagarwal/Library/Developer/Xcode/DerivedData/c-cnyfflmvjyaashaoduqduqqsfegd/Build/Products/Debug/c

Undefined symbols for architecture x86_64:
  "_add_history", referenced from:
      _main in main.o
  "_readline", referenced from:
      _main in main.o
      _source 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)

I am getting Apple-Mach-O Linker (Id) Error, have sent hours trying to fix this one, Dunno what to do.

osgx
  • 90,338
  • 53
  • 357
  • 513
  • 1
    You've already posted this (with an image from your desktop) and it got [removed](http://stackoverflow.com/questions/23313116/getting-apple-mach-o-linker-error-c99-how-do-i-fix-this). You haven't changed anything in this report. – Rich Apr 26 '14 at 16:44

2 Answers2

2

It looks like you are using the GNU readline and GNU history libraries, which are available, by default, on the mac in libedit.dylib:

$ nm /usr/lib/libedit.dylib | fgrep readline
0000000000009899 T _readline
000000000001f444 D _readline_echoing_p
000000000001f400 D _rl_readline_name
000000000001f3f8 D _rl_readline_version
$ nm /usr/lib/libedit.dylib | fgrep add_history
000000000000acbc T _add_history

(the T indicates that the symbol is in the library's text section).

Therefore you need to add -ledit to your linker command line. If you are using Xcode then you can add libedit.dylib to the list of libraries to link against or if you are using make then you probably have to edit the LIBS variable in your Makefile.

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • 2
    If anyone finds this while trying to correct the compile error from reading the text "Build Your Own Lisp", this is the solution. Additionally, you need to remove this line from your code: #include < editline/ history.h > – Brian Yeh Nov 24 '17 at 05:38
0

The error message:

Undefined symbols for architecture x86_64: "_add_history", referenced from: _main in main.o
"_readline", referenced from: _main in main.o _source 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)'

Tells you that the linker cannot find the symbols readline and add_history. Without seeing your source code, and the precise linker and compiler command-lines, it's hard to speculate the exact cause. A likely cause is that you failed to link with external libraries, or other modules of your program.

marko
  • 9,029
  • 4
  • 30
  • 46