Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 使用FANN的链接错误_C_Linker_Mingw_Fann - Fatal编程技术网

C 使用FANN的链接错误

C 使用FANN的链接错误,c,linker,mingw,fann,C,Linker,Mingw,Fann,我正试图用MinGW在Windows上构建一个基本的FANN(快速人工神经网络)项目。然而,每当我尝试链接可执行文件时,我都会遇到一堆未定义的对错误的引用。有趣的是,如果我根本不链接库,我会得到更多的错误,这意味着至少有一些库在工作。我试图编译和链接的文件的代码是: #include "doublefann.h" int main() { const unsigned int num_input_neurons = 9; const unsigned int num_outpu

我正试图用MinGW在Windows上构建一个基本的FANN(快速人工神经网络)项目。然而,每当我尝试链接可执行文件时,我都会遇到一堆未定义的对错误的引用。有趣的是,如果我根本不链接库,我会得到更多的错误,这意味着至少有一些库在工作。我试图编译和链接的文件的代码是:

#include "doublefann.h"

int main() {
    const unsigned int num_input_neurons = 9;
    const unsigned int num_output_neurons = 1;
    const unsigned int num_layers = 3;
    const unsigned int num_hidden_neurons = 9;
    const float desired_error = (const float) 0;
    const unsigned int max_epochs = 500000;
    const unsigned int epochs_between_reports = 1000;

    struct fann *ann = fann_create_standard(num_layers,
                                            num_input_neurons,
                                            num_hidden_neurons,
                                            num_output_neurons);

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

    fann_train_on_file(ann,
                       "titanic-training.data",
                       max_epochs,
                       epochs_between_reports,
                       desired_error);

    fann_save(ann, "titanic.net");

    fann_destroy(ann);

    return 0;
}
gcc -Wall -Ifann\src\include titanic-train.c -Lfann\bin -lfanndouble -o titanic-train.exe
我用来编译和链接的命令是:

#include "doublefann.h"

int main() {
    const unsigned int num_input_neurons = 9;
    const unsigned int num_output_neurons = 1;
    const unsigned int num_layers = 3;
    const unsigned int num_hidden_neurons = 9;
    const float desired_error = (const float) 0;
    const unsigned int max_epochs = 500000;
    const unsigned int epochs_between_reports = 1000;

    struct fann *ann = fann_create_standard(num_layers,
                                            num_input_neurons,
                                            num_hidden_neurons,
                                            num_output_neurons);

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

    fann_train_on_file(ann,
                       "titanic-training.data",
                       max_epochs,
                       epochs_between_reports,
                       desired_error);

    fann_save(ann, "titanic.net");

    fann_destroy(ann);

    return 0;
}
gcc -Wall -Ifann\src\include titanic-train.c -Lfann\bin -lfanndouble -o titanic-train.exe
我得到的错误是:

C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0x7f): undefined reference to `fann_set_activation_function_hidden'           
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0x93): undefined reference to `fann_set_activation_function_output'           
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0xbf): undefined reference to `fann_train_on_file'                            
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0xd3): undefined reference to `fann_save'                                     
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0xdf): undefined reference to `fann_destroy'                                  
c:/fragileprograms/mingw-native/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o: bad reloc address 0x64 in section `.rdata'                                                                                                                 
c:/fragileprograms/mingw-native/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation                   
collect2.exe: error: ld returned 1 exit status 
如果我根本不链接库,我会得到:

C:\Users\kunkelwe\AppData\Local\Temp\ccyOO3jL.o:titanic-train.c:(.text+0x67): undefined reference to `fann_create_standard'
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0x7f): undefined reference to `fann_set_activation_function_hidden'           
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0x93): undefined reference to `fann_set_activation_function_output'           
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0xbf): undefined reference to `fann_train_on_file'                            
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0xd3): undefined reference to `fann_save'                                     
C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o:titanic-train.c:(.text+0xdf): undefined reference to `fann_destroy'                                  
c:/fragileprograms/mingw-native/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\kunkelwe\AppData\Local\Temp\ccsWQg66.o: bad reloc address 0x64 in section `.rdata'                                                                                                                 
c:/fragileprograms/mingw-native/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation                   
collect2.exe: error: ld returned 1 exit status
编辑:

根据Haroogan的请求,我运行了
nmfanddouble.lib
。输出相当广泛,因此我没有将其全部粘贴到此处,而是通过pastebin将其提供到此处:

我不熟悉
nm
,但文件中似乎确实存在缺少的符号

编辑#2:

doublefann.h的内容如下:

以及fann.h的内容,包括:

这个问题可以通过使用MinGW重新编译库来解决吗

编辑#3:

哈鲁根建议的改变奏效了!除了这些更改,我还必须通过添加以下内容来修改FANN的CMakeLists.txt文件:

if (WIN32)
ADD_DEFINITIONS(-DFANN_DLL_EXPORTS)
endif (WIN32)

然后,在项目的根目录中运行
cmake-G“MinGW Makefiles”
,然后运行
mingw32 make
,生成一个文件libdoublefann.dll,当该文件链接到.exe目录并包含在该目录中时,最终允许我运行我的程序。

doublefann.h
的第116行:

改为:

#if (_MSC_VER > 1300) || defined(__MINGW32__) || defined(__MINGW64__)
#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)) && \
    (defined(FANN_USE_DLL) || defined(FANN_DLL_EXPORTS))
此外,在第121行:

改为:

#if (_MSC_VER > 1300) || defined(__MINGW32__) || defined(__MINGW64__)
#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)) && \
    (defined(FANN_USE_DLL) || defined(FANN_DLL_EXPORTS))

运行
nm libfanndouble.a
,查看缺少的符号是否在库中定义。完成后,用结果更新您的问题,以便我们可以考虑下一步做什么。@Haroogan:done。顺便说一句,这是FandDouble.lib,而不是libFandDouble.aThis。这是一个典型的问题,不同编译器的问题有所不同。显然,
fanddouble.lib
fanddouble.dll
都是由MSVC编译器生成的,因此,由于不同的名称损坏约定,现在您很难直接链接到MinGW。但别担心,我们会解决的。首先,让我们看看你的
floatfann.h
。哎呀,我没意识到这里的代码上写着
“floatfann.h”
;我已经将它从
“doublefann.h”
改为测试链接是否与FanFloat库一起工作。谢谢。我遇到了一个(可能)与MinGW无关的问题,所以我可能需要一段时间才能做到这一点。