【问题标题】:Raspberry Pi 3 ,fann_create_standard not defined树莓派 3,fann_create_standard 未定义
【发布时间】:2017-06-07 06:20:05
【问题描述】:

我最近通过树莓派的突触管理器下载了 FANN(快速人工神经网络)库。我正在尝试运行如下所示的默认应用程序:

 #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;
}

我得到这个输出:

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)) ===|

还尝试使用gcc 链接库,如下所示:

gcc -lfann main.c

不知道该怎么办。

【问题讨论】:

    标签: c++ c gcc linker raspberry-pi


    【解决方案1】:

    我相信,您需要更改库在编译语句中出现的顺序。

     gcc -lfann main.c
    

    应该是

     gcc main.c -lfann
    

    因为main.c 中使用的函数存在于libfann.so 中。

    引用online gcc manual

    -l library

    [....] 在命令中编写此选项的位置有所不同;链接器按照指定的顺序搜索和处理库和目标文件。因此,foo.o -lz bar.o 在文件foo.o 之后但在bar.o 之前搜索库z。如果bar.o 引用了z 中的函数,则这些函数可能不会被加载。

    在您的情况下,您面临类似的情况,对于您的情况,库应该出现在 main.c 之后,因为库中的函数在 main.c 中使用

    【讨论】:

    • 如果有帮助,版本是 2.1.0。
    • 我这样做了,但终端没有输出
    • Nvm,知道了。需要输入 ./a.out 输出
    • @乔恩酷!!也可以考虑accepting an answer that helped you
    猜你喜欢
    • 2018-02-07
    • 2017-03-30
    • 2023-01-30
    • 1970-01-01
    • 2016-11-11
    • 2019-08-08
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多