gpt4 book ai didi

c++ - Raspberry Pi 3,fann_create_standard 未定义

转载 作者:行者123 更新时间:2023-11-30 16:44:40 25 4
gpt4 key购买 nike

我最近通过树莓派的突触管理器下载了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

不知道该怎么做。

最佳答案

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

 gcc -lfann main.c

应该是

 gcc main.c -lfann

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

引用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.

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

关于c++ - Raspberry Pi 3,fann_create_standard 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44404947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com