4

I've downloaded and compiled: http://leenissen.dk/fann/wp/

  • cmake version 2.8.11.2
  • gcc (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1

Command used to compile:

cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr .

Installation:

sudo make && sudo make install

Then I go to examples/ directory inside fann project and try to compile examples by running:

make all

I'm getting an error:

gcc -O3 xor_train.c -o xor_train -lfann -lm
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `sin'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `exp'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `cos'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `log'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `pow'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `sqrt'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `floor'
collect2: error: ld returned 1 exit status
make: *** [xor_train] Error 1

Update:

  • I've followed an instruction given by a library
  • I've checked on another machine and provided instruction works as intended so I guess my environment is in a some way misconfigured.

Some more info about shared library dependencies:

ldd /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so
    linux-vdso.so.1 =>  (0x00007fff3abfe000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6f3997c000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f6f39f84000)

As suggested by @michael-burr compiled with -Wl,-v

/usr/bin/ld --sysroot=/ \
  --build-id --eh-frame-hdr -m elf_x86_64 \
  --hash-style=gnu --as-needed \
  -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
  -z relro -o xor_train \
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o \
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o \
  /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o \
  -L/usr/lib/gcc/x86_64-linux-gnu/4.8 \
  -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu \
  -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib \
  -L/lib/x86_64-linux-gnu \
  -L/lib/../lib -L/usr/lib/x86_64-linux-gnu \
  -L/usr/lib/../lib \
  -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. \
  -v /tmp/cc0AHZgU.o -lfann -lm -lgcc --as-needed -lgcc_s --no-as-needed \
  -lc -lgcc --as-needed -lgcc_s --no-as-needed \
  /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o \
  /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
GNU ld (GNU Binutils for Ubuntu) 2.23.52.20130913
Paweł Szczur
  • 5,484
  • 3
  • 29
  • 32
  • 1
    possible duplicate of [Undefined reference to \`sin\` in C](http://stackoverflow.com/questions/5005363/undefined-reference-to-sin-in-c) – Zach Stark Oct 30 '13 at 21:11
  • 4
    @ZachStark No, it's not a duplicate. I'm adding correct library and a compilation options are in a correct order. I've spend a lot of time getting through all similar questions. No one have same problem. – Paweł Szczur Oct 30 '13 at 21:13
  • 1
    Adding the `-Wl,--verbose` and/or `-v` options to gcc might give a clue about what the problem is with whatever libm library is being searched. – Michael Burr Oct 30 '13 at 21:24
  • 1
    Note that `-Wl,-v` (option to ld to display it's version) is different than `-Wl,--verbose` (option to ld to be verbose) and `-v` (option to gcc to be verbose). – Michael Burr Oct 30 '13 at 22:04
  • @MichaelBurr I've pasted results here https://gist.github.com/orian/7242125#file-gistfile1-txt – Paweł Szczur Oct 30 '13 at 23:34
  • I've created dump program using math.c and then printed dependencies, it has a line: libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 But as written in the question, libfann.so doesn't have such dependency. – Paweł Szczur Oct 30 '13 at 23:45
  • Done my homework, it looks like missing "inter library dependency": http://www.gnu.org/software/libtool/manual/html_node/Inter_002dlibrary-dependencies.html – Paweł Szczur Oct 31 '13 at 01:09

2 Answers2

5

Root cause: missing dependencies in FANN library (Will send a patch to author). Such a dependency is called "inter library dependency".

It may happen that one build a shared library A and doesn't have correct dependencies set (let's say B). In such a case a shared library A will be build without any error msg as it's not required to provide implementation during compiling.

The problem will appear as a lack of library B when one try to create an executable file which depends on A.

In this specific case a solution is to modify a CMake configuration file according to CMake manual

Example changeline:

TARGET_LINK_LIBRARIES(fann m)
Paweł Szczur
  • 5,484
  • 3
  • 29
  • 32
  • I happen to have the same problem. Can you tell me what I really need to do to fix it? The question seems to have something like an answer attached, but it doesn't seem to apply to me. – Simon Kuang Dec 27 '13 at 18:01
  • 2
    Here's my copy of FANN with updated CMakeList.txt to include -lm as a dependency: https://github.com/orian/fann-1 (I compile it on Ubuntu with commands recommended by author) – Paweł Szczur Dec 30 '13 at 11:28
0

It looks like you're compiling your own program as 64-bit, but the FANN library is 32-bit. You might need to specify an architecture for FANN when you compile, which might mean modifying GCC flags in the makefile, unless there are autoconf settings to do it for you. Assuming that you want 64-bit FANN.

Alternatively, you could specify 32-bit architecture when you compile your own code.

paddy
  • 60,864
  • 6
  • 61
  • 103