简体   繁体   English

在Linux环境下无法在OSX终端上编译代码的困难

[英]Difficulty in compiling code on OSX terminal that works in Linux environment

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. 我正在使用一些有效的代码(我没有写过,并且创建者不在了),以尝试使用终端在Mac(10.9.5)上进行编译。 I'm getting the following error when compiling ( gcc -o code code.c ): 编译时出现以下错误( 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> ) 但出现fatal error: 'readline.h' file not found (与#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? 我的问题仅仅是Mac需要安装一个额外的库才能使用这5个导致错误的功能,还是我的#include之一仅适用于Linux而不适用于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. 我认为既然Mac和Linux都使用Unix,那将是相同的,但是显然有些细微之处我不了解。

Thanks in advance. 提前致谢。

Did you bass the correct flags to the compiler? 您是否向编译器添加了正确的标志? Seems like you are not linking against the libedit . 似乎您没有链接到libedit Try passing -ledit to the compiler and tell us if that helps. 尝试将-ledit传递给编译器,并告诉我们是否有帮助。

#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. 您无法#include一个库,您需要在调用该库时告诉编译器您要链接到该库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM