user840718
user840718

Reputation:

Undefined reference to Eclipse C++

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)".

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.

Can anybody help me?

Upvotes: 5

Views: 34274

Answers (2)

user8396969
user8396969

Reputation:

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.

To those who may be also suffering from this type of errors, try these steps:

  1. 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)
  2. C/C++ Build->settings->gcc linker, see right there is a "+", click and type ssl and crypto
  3. Rebuild your project, done.

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.

A good resource for gcc command: https://www.rapidtables.com/code/linux/gcc/gcc-l.html

Upvotes: 0

akappa
akappa

Reputation: 10490

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:

  1. Right-click on the project, then select Properties
  2. Go under C/C++ Build -> Settings
  3. Select GCC C Linker -> Libraries
  4. In Libraries (-l), add the name of your libraries,
  5. If needed, put the directory where your libraries are hosted in Library search path (-L).

Upvotes: 18

Related Questions