2

When I compiled my program and ran it, I got a a symbol lookup error. I was doing this:

$ gcc -o parts parts.c -lnettle $ ./parts $ ./parts: symbol lookup error: ./parts: undefined symbol: nettle_pbkdf2 

My code included these header files:

#include <nettle/pbkdf2.h> #include <nettle/hmac.h> #include <pbkdf2-hmac-sha1.c> 

I solved my problem by including the object files for the two included header files during gcc compilation.

$ gcc -o parts parts.c hmac.o pbkdf2.o -lnettle 

The thing is, I don't understand what is going on and therefore why this works. Why must I include the .o files and not just the header files to avoid symbol lookup or undefined reference errors?

2
  • 2
    The headers tell you what is defined. The object files provide the actual definition. Commented Feb 17, 2014 at 0:34
  • What do you put in your source files, that you think is so unnecessary? Commented Feb 17, 2014 at 0:34

1 Answer 1

2

As Tobias mentioned, a header file tells the compiler what is done, the object file tells the compiler how it is done. You can see here what an object file is, but in reality it's just a precompiled version of a source file.

Truly, you were not actually getting compiler errors, but linker errors. It knew how to compile your source file, but it couldn't put everything together until it got the other object files.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I did some more reading on the whole linker process and it's becoming clearer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.