对 Eclipse C++ 的未定义引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7860657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Undefined reference to Eclipse C++
提问by akappa
I've tried more and more time, but I got the same error. When I use an external lib, for example I'm try to work on openssl and crypto++, I receive the error: "undefined reference to (function)".
我已经尝试了越来越多的时间,但我遇到了同样的错误。例如,当我使用外部库时,我尝试使用 openssl 和 crypto++,我收到错误:“对(函数)的未定义引用”。
I dunno why Eclipse do that neverthless the #include are all correct. I've tried even to add the path from Properties-C/C++ General-Path & Symbols but nothing.
我不知道为什么 Eclipse 会这样做,但 #include 都是正确的。我什至尝试从 Properties-C/C++ General-Path & Symbols 添加路径,但什么也没有。
Can anybody help me?
有谁能够帮助我?
回答by akappa
You must specify the name of the shared libraries which must be linked to the executable.
您必须指定必须链接到可执行文件的共享库的名称。
Assuming you are using the GNU toolchain, you can do it by following these steps:
假设您使用的是 GNU 工具链,您可以按照以下步骤操作:
- Right-click on the project, then select
Properties
- Go under
C/C++ Build
->Settings
- Select
GCC C Linker
->Libraries
- In
Libraries (-l)
, add the name of your libraries, - If needed, put the directory where your libraries are hosted in
Library search path (-L)
.
- 右键单击项目,然后选择
Properties
- 进入
C/C++ Build
->Settings
- 选择
GCC C Linker
->Libraries
- 在 中
Libraries (-l)
,添加您的库的名称, - 如果需要,将库所在的目录放在
Library search path (-L)
.
回答by akappa
I have the same problem too. I was using Eclipse CDT
and trying to build my source code with OpenSSL
headers and I got the same "undefined reference"
problem.
我也有同样的问题。我正在使用Eclipse CDT
并尝试使用OpenSSL
标头构建我的源代码,但我遇到了同样的"undefined reference"
问题。
To those who may be also suffering from this type of errors, try these steps:
对于那些可能也遭受此类错误的人,请尝试以下步骤:
- Make sure you use the right compiler(for
Ubuntu 18.04
)right click your project->preference->C/C++ Build->tool chain editor->use CDT internal Builder / Linux gcc
(you can try to run HelloWorld as a test) C/C++ Build->settings->gcc linker
, see right there is a"+"
, click and typessl
andcrypto
- Rebuild your project, done.
- 确保使用正确的编译器(for
Ubuntu 18.04
)right click your project->preference->C/C++ Build->tool chain editor->use CDT internal Builder / Linux gcc
(您可以尝试运行 HelloWorld 作为测试) C/C++ Build->settings->gcc linker
, 看到右边有一个"+"
, 单击并键入ssl
和crypto
- 重建你的项目,完成。
I strongly recommend you to learn gcc compiler command line. If you have compile problem, always use the terminal and command line to see if you can compile it successfully, then compare the succeeded command with the console log in Eclipse, at where you can see the actual gcc command that used to compile your code.
我强烈建议你学习 gcc 编译器命令行。如果你有编译问题,总是使用终端和命令行查看是否可以编译成功,然后将成功的命令与 Eclipse 中的控制台日志进行比较,在那里你可以看到用于编译代码的实际 gcc 命令。
A good resource for gcc command: https://www.rapidtables.com/code/linux/gcc/gcc-l.html
gcc 命令的好资源:https: //www.rapidtables.com/code/linux/gcc/gcc-l.html