0

MinGW を使用して Windows で基本的な FANN (高速人工ニューラル ネットワーク) プロジェクトを構築しようとしています。ただし、実行可能ファイルをリンクしようとするたびに、一連のundefined reference toエラーが発生します。興味深いことに、ライブラリをまったくリンクしないと、ライブラリの少なくとも一部が機能していることを意味するエラーがさらに発生します。コンパイルしてリンクしようとしているファイルのコードは次のとおりです。

#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

編集:

ハルーガンの頼みで走っnm fanndouble.libた。出力はかなり広範囲なので、ここにすべてを貼り付けるのではなく、こちらの Pastebin 経由で利用できるようにしました: http://pastebin.com/raw.php?i=vybFhEcX

については詳しくありませんnmが、不足しているシンボルがファイルに存在するようです。

編集#2:

doublefann.h の内容は次のとおりです。http://pastebin.com/mrHKJi8C

含まれるfann.hの内容は次のとおりです。http://pastebin.com/gTrHCYAg

この問題は、ライブラリを MinGW で再コンパイルするだけで解決できますか?

編集#3:

Haroogan が提案した変更を行うと、うまくいきました。これらの変更に加えて、FANN の CMakeLists.txt ファイルを次のように変更する必要がありました。

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

次に、プロジェクトのルートで実行するcmake -G "MinGW Makefiles"mingw32-make、ファイル libdoublefann.dll が生成され、.exe のディレクトリにリンクされて含まれていると、最終的にプログラムを実行できるようになりました。

4

1 に答える 1

1

116doublefann.h行目:

#if (_MSC_VER > 1300)

への変更:

#if (_MSC_VER > 1300) || defined(__MINGW32__) || defined(__MINGW64__)

さらに、行番号 121 で:

#if defined(_MSC_VER) && (defined(FANN_USE_DLL) || defined(FANN_DLL_EXPORTS))

への変更:

#if (defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)) && \
    (defined(FANN_USE_DLL) || defined(FANN_DLL_EXPORTS))
于 2013-10-11T13:08:09.620 に答える