Search code examples
ubuntuqt-creatorfann

how to add FANN library in QT Creator in linux


i'm trying to use fann library in qt environment.i make a project to test a simple example of fann and add "LIBS += -L/usr/local/lib -lfann" to ".pro file" but whenever try to run example i countered with this error :

undefined reference to 'sin'      libfann.so
undefined reference to 'exp'      libfann.so
undefined reference to 'log'      libfann.so
undefined reference to 'cos'      libfann.so
undefined reference to 'pow'      libfann.so
undefined reference to 'sqrt'     libfann.so
undefined reference to 'floor'    libfann.so

. . . it seems there is a problem with mathematics function,but how should fix it?


Solution

  • Ok, eventually found the mistake. It is a matter of linking the library.

    There are several ways to solve it:

    1. Copy the required .h and .c file from fann and add them into your project(for example if you run xor example you should copy and paste the fann.h and fann.c directly to your project)

    2. The better way: Build the static library "libfann.a" and add it to the project.

      • Build it, following:

      • Add it:

        • with Qmake: if your libfann.so installed in "usr/local/lib", use "LIBS += -L/usr/local/lib -lfann" instead of "LIBS += -lfann"
        • with Cmake: add the last two lines
          # after add_executable(${PROJECT_NAME} "main.cpp") link_directories(/usr/local/lib) # -L flags target_link_libraries(${PROJECT_NAME} fann) # -l flags