简体   繁体   中英

Raspberry Pi 3 ,fann_create_standard not defined

I recently downloaded the FANN(Fast artificial neural network) library via the synaptic manager for raspberry pi. I am trying to run the default application as shown below:

 #include "fann.h"
 #include "floatfann.h"
 include "fann_data.h"

 int main()
 {
const unsigned int num_input = 2;
const unsigned int num_output = 1;
const unsigned int num_layers = 3;
const unsigned int num_neurons_hidden = 3;
const float desired_error = (const float) 0.001;
const unsigned int max_epochs = 500000;
const unsigned int epochs_between_reports = 1000;

struct fann *ann = fann_create_standard(num_layers, num_input,
    num_neurons_hidden, num_output);

fann_set_activation_function_hidden(ann, FANN_SIGMOID_SYMMETRIC);
fann_set_activation_function_output(ann, FANN_SIGMOID_SYMMETRIC);

fann_train_on_file(ann, "xor.data", max_epochs,
    epochs_between_reports, desired_error);

fann_save(ann, "xor_float.net");

fann_destroy(ann);

return 0;
}

I am getting this output:

enter code here


||=== Build: Debug in ArtificialNeuralNetworkExample (compiler: GNU GCC    Compi ler) ===|
obj/Debug/main.o||In function `main':|
/home/pi/Documents/ArtificialNeuralNetworkExample/main.c|14|undefined reference to `fann_create_standard'|
/home/pi/Documents/ArtificialNeuralNetworkExample/main.c|17|undefined reference to `fann_set_activation_function_hidden'|
/home/pi/Documents/ArtificialNeuralNetworkExample/main.c|18|undefined reference to `fann_set_activation_function_output'|
/home/pi/Documents/ArtificialNeuralNetworkExample/main.c|20|undefined reference to `fann_train_on_file'|
/home/pi/Documents/ArtificialNeuralNetworkExample/main.c|23|undefined reference to `fann_save'|
/home/pi/Documents/ArtificialNeuralNetworkExample/main.c|25|undefined reference to `fann_destroy'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

Also tried linking the library using gcc as follows:

gcc -lfann main.c

Not sure what to do.

I believe, you need to change the order in which the library appears in the compilation statement.

 gcc -lfann main.c

should be

 gcc main.c -lfann

as the functions used in main.c are present in libfann.so .

Quoting the online gcc manual ,

-l library

[....] It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o . If bar.o refers to functions in z , those functions may not be loaded.

In your case, you're facing similar scenario, for your case, the library should appear after the main.c as the functions from the library are used in main.c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM