-1

I'm trying to run a program in Code::Blocks, and in my program I have used the hash functions, such as hsearch and hcreate, but Code::Blocks seems to not allow them.

I have the header:

#include <search.h>    

included already, but errors such as "undefined reference to 'hsearch' " still comes up.

Is there anyway to allow these functions to run in Code::Blocks at all?

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
Boku
  • 63
  • 9
  • 2
    "*undefined reference*" is linker error. – alk May 25 '16 at 10:44
  • Where did you get the library from? It seems like it is misconfigured, and the linker can't link it. – meskobalazs May 25 '16 at 10:45
  • @meskobalazs The search.h was obtained from the man page [Here](http://linux.die.net/man/3/hcreate) – Boku May 25 '16 at 10:51
  • 1
    Are you running linux or windows? The function is in the standard libc. On linux it should run "out of the box". See https://ideone.com/mr06W3 I just pasted the example from the man page into. – kwarnke May 25 '16 at 11:00
  • `search.h` is not a library, but a so called "header file", which in fact is a C source file. It only provides the "interface" of what a specific object or library implements, so that the compiler knows about it. When the compiler is done in a final step all objects/libraries needed are linked together with what the compiler produced, to create the final program. – alk May 25 '16 at 11:08
  • @kwarnke I'm running on windows, hence using codeblock IDE to do my coding. I think is the problem, but is there a way around it? – Boku May 25 '16 at 11:42

1 Answers1

1

Header files are just containing the declarations. You need to have the libraries installed, which are containing the implementation.

And that what it is telling you. It found the declarations just fine, however the linker did not find the libraries, hence the linkage error.

On Linux, the search.h and its implementation is part of the libc, so it is already ready to use. On Windows, however, you need to get a binary version of it, set up the library path for Code::Blocks, and use the linker options in the settings.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
  • Ahhh yes, this is what I'm looking for. I'll search on the web a bit, and see if I can find it and get it working. Thank you so much! – Boku May 25 '16 at 11:43