Question

I have built the FreeBSD libfortuna library under Linux. What I did to manage it was just to comment #include <malloc_np.h> in src/px.h and src/internal.h, and do make, make install, and create a symlink of the library in my system standard paths.

Then, I have written a small test program for it:

#include <cstdlib>
#include <fortuna.h>

int main () {
  int i = 0;
  fortuna_get_bytes (4, (unsigned char *) &i);
  printf ("test fortuna i = %d \n", i);
  return 0;
}

Then compile and link with:

g++ -I/usr/local/include/fortuna -O0 -g3 -Wall -fmessage-length=0 -c test.cpp
g++ -g -L/usr/local/lib/ -o test test.o -lfortuna
test.o: In function `main':
/home/alain/Documents/Poker/WorkSpace/libfortuna/test/test.cpp:14: undefined reference to `fortuna_get_bytes(unsigned int, unsigned char*)'
collect2: ld returned 1 exit status

I tried also -L/usr/lib/ where my simlink is, but with the same result.

I tried also with gcc instead of g++, but with also the same result.

I checked that the library is in the path:

# ls -l /usr/lib/libfortuna.so
lrwxrwxrwx 1 root root 28 26 avril 17:27 /usr/lib/libfortuna.so -> /usr/local/lib/libfortuna.so

I checked that the symbol fortuna_get_bytes is defined in the binary file:

$ objdump -T /usr/local/lib/libfortuna.so  | grep fortuna
/usr/local/lib/libfortuna.so:     file format elf64-x86-64
0000000000005000 g    DF .text  000000000000007f  Base        fortuna_get_bytes
0000000000004f80 g    DF .text  000000000000007d  Base        fortuna_add_entropy
$ nm -g -C /usr/local/lib/libfortuna.so | grep fortuna
0000000000004f80 T fortuna_add_entropy
0000000000005000 T fortuna_get_bytes

I don't know what to do more. A few clues are welcome please.

Was it helpful?

Solution

Examining the Fortuna source, it is a C library with no compatibility code for C++; it looks to me like this is causing you problems with calling conventions and name mangling.

C++ is not C.

You could try:

extern "C" {
   #include <fortuna.h>
}

to force the library's declarations to be brought into your code with C linkage, but this is a bit of a hack. Ideally the library's headers would use this technique internally to enable C++ compatibility, per convention.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top