I'm taking some working code (that I didn't write and the creator is not around anymore) to try and get it to compile on my Mac (10.9.5) using terminal. I'm getting the following error when compiling ( gcc -o code code.c
):
Undefined symbols for architecture x86_64:
"_add_history", referenced from:
_rl_gets in talk-c856c6.o
"_read_history", referenced from:
_main in talk-c856c6.o
"_readline", referenced from:
_rl_gets in talk-c856c6.o
"_write_history", referenced from:
_rl_gets in talk-c856c6.o
ld: symbol(s) not found for architecture x86_64
here are all my includes:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <strings.h>
#include <readline/readline.h>
#include <readline/history.h>
I've found here and elsewhere online similar issues and have tried
#include <readline.h>
but get fatal error: 'readline.h' file not found
(same for #include <libedit.dylib>
)
I'm a bit of a novice with external libraries so maybe I need to install another one? Is my issue just that the mac needs an additional library installed to use those 5 functions creating errors, or are one of my #includes only for Linux and not for Mac? I thought since both the Mac and the Linux are using Unix it would be the same, but apparently there are subtleties I don't understand.
Thanks in advance.
Did you bass the correct flags to the compiler? Seems like you are not linking against the libedit
. Try passing -ledit
to the compiler and tell us if that helps.
#include <libedit.dylib>
This is never correct. You can't #include
a library, you need to tell the compiler that you want to link against this library when invoking it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.