Skip to content
Advertisement

How to use FANN in C++

Here I have read good references about FANN for Artificial Neural Networks in C/C++. Actually I am using C++ (on Ubuntu with g++ v4.6.1). The library written in C, has a wrapper for C++. But I don’t get it to work. Even the example included xor_sample.cpp works.

I have a Makefile with a line like this:

xor_sample:
    g++ -I $(FANNINCLUDE) xor_sample.cpp -o xor_sample

Being FANNINCLUDE the path to FANN/src/include, where the headers are (floatfan.h and fann_cpp.h).

Has somebody actually compiled it for C++? What I am doing wrong? My intention is to use the headers files (NOT installing the library and linking with –lfann). Is this possible?

EDIT: I get this errors

/tmp/ccIpH6p4.o: In function `FANN::training_data::destroy_train()':
xor_sample.cpp:(.text._ZN4FANN13training_data13destroy_trainEv[FANN::training_data::destroy_train()]+0x18): undefined reference to `fann_destroy_train'
/tmp/ccIpH6p4.o: In function `FANN::training_data::read_train_from_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
xor_sample.cpp:(.text._ZN4FANN13training_data20read_train_from_fileERKSs[FANN::training_data::read_train_from_file(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x20): undefined reference to `fann_read_train_from_file'
/tmp/ccIpH6p4.o: In function `FANN::training_data::save_train_to_fixed(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)':
xor_sample.cpp:(.text._ZN4FANN13training_data19save_train_to_fixedERKSsj[FANN::training_data::save_train_to_fixed(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)]+0x37): undefined reference to `fann_save_train_to_fixed'
/tmp/ccIpH6p4.o: In function `FANN::training_data::length_train_data()':
xor_sample.cpp:(.text._ZN4FANN13training_data17length_train_dataEv[FANN::training_data::length_train_data()]+0x1f): undefined reference to `fann_length_train_data'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::destroy()':
xor_sample.cpp:(.text._ZN4FANN10neural_net7destroyEv[FANN::neural_net::destroy()]+0x18): undefined reference to `fann_get_user_data'
xor_sample.cpp:(.text._ZN4FANN10neural_net7destroyEv[FANN::neural_net::destroy()]+0x39): undefined reference to `fann_destroy'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::create_standard_array(unsigned int, unsigned int const*)':
xor_sample.cpp:(.text._ZN4FANN10neural_net21create_standard_arrayEjPKj[FANN::neural_net::create_standard_array(unsigned int, unsigned int const*)]+0x1f): undefined reference to `fann_create_standard_array'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::run(float*)':
xor_sample.cpp:(.text._ZN4FANN10neural_net3runEPf[FANN::neural_net::run(float*)]+0x26): undefined reference to `fann_run'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::init_weights(FANN::training_data const&)':
xor_sample.cpp:(.text._ZN4FANN10neural_net12init_weightsERKNS_13training_dataE[FANN::neural_net::init_weights(FANN::training_data const&)]+0x2a): undefined reference to `fann_init_weights'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::save(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
xor_sample.cpp:(.text._ZN4FANN10neural_net4saveERKSs[FANN::neural_net::save(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x30): undefined reference to `fann_save'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::save_to_fixed(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
xor_sample.cpp:(.text._ZN4FANN10neural_net13save_to_fixedERKSs[FANN::neural_net::save_to_fixed(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x30): undefined reference to `fann_save_to_fixed'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::train_on_data(FANN::training_data const&, unsigned int, unsigned int, float)':
xor_sample.cpp:(.text._ZN4FANN10neural_net13train_on_dataERKNS_13training_dataEjjf[FANN::neural_net::train_on_data(FANN::training_data const&, unsigned int, unsigned int, float)]+0x3f): undefined reference to `fann_train_on_data'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::get_MSE()':
xor_sample.cpp:(.text._ZN4FANN10neural_net7get_MSEEv[FANN::neural_net::get_MSE()]+0x20): undefined reference to `fann_get_MSE'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::set_callback(int (*)(FANN::neural_net&, FANN::training_data&, unsigned int, unsigned int, float, unsigned int, void*), void*)':
xor_sample.cpp:(.text._ZN4FANN10neural_net12set_callbackEPFiRS0_RNS_13training_dataEjjfjPvES4_[FANN::neural_net::set_callback(int (*)(FANN::neural_net&, FANN::training_data&, unsigned int, unsigned int, float, unsigned int, void*), void*)]+0x1c): undefined reference to `fann_get_user_data'
xor_sample.cpp:(.text._ZN4FANN10neural_net12set_callbackEPFiRS0_RNS_13training_dataEjjfjPvES4_[FANN::neural_net::set_callback(int (*)(FANN::neural_net&, FANN::training_data&, unsigned int, unsigned int, float, unsigned int, void*), void*)]+0x81): undefined reference to `fann_set_user_data'
xor_sample.cpp:(.text._ZN4FANN10neural_net12set_callbackEPFiRS0_RNS_13training_dataEjjfjPvES4_[FANN::neural_net::set_callback(int (*)(FANN::neural_net&, FANN::training_data&, unsigned int, unsigned int, float, unsigned int, void*), void*)]+0x9c): undefined reference to `fann_set_callback'
xor_sample.cpp:(.text._ZN4FANN10neural_net12set_callbackEPFiRS0_RNS_13training_dataEjjfjPvES4_[FANN::neural_net::set_callback(int (*)(FANN::neural_net&, FANN::training_data&, unsigned int, unsigned int, float, unsigned int, void*), void*)]+0xb3): undefined reference to `fann_set_callback'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::print_parameters()':
xor_sample.cpp:(.text._ZN4FANN10neural_net16print_parametersEv[FANN::neural_net::print_parameters()]+0x18): undefined reference to `fann_print_parameters'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::set_learning_rate(float)':
xor_sample.cpp:(.text._ZN4FANN10neural_net17set_learning_rateEf[FANN::neural_net::set_learning_rate(float)]+0x1f): undefined reference to `fann_set_learning_rate'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::set_activation_function_hidden(FANN::activation_function_enum)':
xor_sample.cpp:(.text._ZN4FANN10neural_net30set_activation_function_hiddenENS_24activation_function_enumE[FANN::neural_net::set_activation_function_hidden(FANN::activation_function_enum)]+0x1f): undefined reference to `fann_set_activation_function_hidden'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::set_activation_function_output(FANN::activation_function_enum)':
xor_sample.cpp:(.text._ZN4FANN10neural_net30set_activation_function_outputENS_24activation_function_enumE[FANN::neural_net::set_activation_function_output(FANN::activation_function_enum)]+0x1f): undefined reference to `fann_set_activation_function_output'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::set_activation_steepness_hidden(float)':
xor_sample.cpp:(.text._ZN4FANN10neural_net31set_activation_steepness_hiddenEf[FANN::neural_net::set_activation_steepness_hidden(float)]+0x1f): undefined reference to `fann_set_activation_steepness_hidden'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::set_activation_steepness_output(float)':
xor_sample.cpp:(.text._ZN4FANN10neural_net31set_activation_steepness_outputEf[FANN::neural_net::set_activation_steepness_output(float)]+0x1f): undefined reference to `fann_set_activation_steepness_output'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::get_network_type()':
xor_sample.cpp:(.text._ZN4FANN10neural_net16get_network_typeEv[FANN::neural_net::get_network_type()]+0x1f): undefined reference to `fann_get_network_type'
/tmp/ccIpH6p4.o: In function `FANN::neural_net::internal_callback(fann*, fann_train_data*, unsigned int, unsigned int, float, unsigned int)':
xor_sample.cpp:(.text._ZN4FANN10neural_net17internal_callbackEP4fannP15fann_train_datajjfj[FANN::neural_net::internal_callback(fann*, fann_train_data*, unsigned int, unsigned int, float, unsigned int)]+0xe): undefined reference to `fann_get_user_data'
collect2: ld returned 1 exit status
make: *** [xor_sample] Error 1

Advertisement

Answer

if you just need them installed, they are already on ubuntu repository

sudo apt-get install libfann1 libfann1-dev

if you still want to install it from source, there’s a guide on their page http://leenissen.dk/fann/wp/help/installing-fann/ if this doesn’t bring you further, try installing to other location using: cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr .

Hope this helps

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement