我正在使用FANN(http://leenissen.dk/fann/wp/download/)。这两个标题都可以在存档中找到,你可以在那里下载(我希望我不会给你带来太多麻烦)。
/*
* File: main.cpp
* Author: johannsebastian
*
* Created on November 26, 2013, 8:50 PM
*/
#include "../FANN-2.2.0-Source/src/include/doublefann.h"
#include "../FANN-2.2.0-Source/src/include/fann_cpp.h"
#include <cstdlib>
#include <iostream>
using namespace std;
using namespace FANN;
/*
*
*/
//Remember: fann_type is double!
int main(int argc, char** argv) {
neural_net * N = new neural_net;
const unsigned int myLayerArray[4] = {1,2,2,1};
const unsigned int numLayers = 4;
N->create_standard(3,1,2,1);
cout<<"Easy!";
return 0;
}
g ++说
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/bachnet
make[2]: Entering directory `/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/bachnet build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `FANN::neural_net::destroy()':
/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet/../FANN-2.2.0-Source/src/include/fann_cpp.h:915: undefined reference to `fann_get_user_data'
/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet/../FANN-2.2.0-Source/src/include/fann_cpp.h:919: undefined reference to `fann_destroy'
build/Debug/GNU-Linux-x86/main.o: In function `FANN::neural_net::create_standard_array(unsigned int, unsigned int const*)':
/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet/../FANN-2.2.0-Source/src/include/fann_cpp.h:979: undefined reference to `fann_create_standard_array'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/bachnet] Error 1
make[2]: Leaving directory `/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/johannsebastian/Desktop/heatmap3d/BACHnet/BACHnet'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 773ms)
你可以帮我解决这个问题吗?我想我可能有一些基本的编译器配置错误或其他什么。
答案 0 :(得分:2)
ld
)。-lFANN
)和库的路径(例如-L/path/path/path
。。您也可以在$LD_LIBRARY_PATH
系统中指定的路径变量,那么你不需要-L
选项)。此外,您必须先安装(编译)库本身才能使用它。您有安装指南here。该指南适合我:
下载FANN-2.2.0-Source。
使用cmake安装它:
[08:42:24]~/Downloads$ cd FANN-2.2.0-Source/
[08:42:27]~/Downloads/FANN-2.2.0-Source$ ls
CMakeLists.txt README.txt bin datasets src
COPYING.txt VS2010 cmake examples
[08:42:27]~/Downloads/FANN-2.2.0-Source$ cmake .
-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /opt/local/bin/gcc
-- Check for working C compiler: /opt/local/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /<...>g++
-- Check for working CXX compiler: /<...>g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- FANN is used as APPLICATION_NAME
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ikulakov/Downloads/FANN-2.2.0-Source
[08:43:57]~/Downloads/FANN-2.2.0-Source$ make
Scanning dependencies of target doublefann
[ 25%] Building C object src/CMakeFiles/doublefann.dir/doublefann.c.o
Linking C shared library libdoublefann.dylib
[ 25%] Built target doublefann
Scanning dependencies of target fann
[ 50%] Building C object src/CMakeFiles/fann.dir/floatfann.c.o
Linking C shared library libfann.dylib
[ 50%] Built target fann
Scanning dependencies of target fixedfann
[ 75%] Building C object src/CMakeFiles/fixedfann.dir/fixedfann.c.o
Linking C shared library libfixedfann.dylib
[ 75%] Built target fixedfann
Scanning dependencies of target floatfann
[100%] Building C object src/CMakeFiles/floatfann.dir/floatfann.c.o
Linking C shared library libfloatfann.dylib
[100%] Built target floatfann
[08:44:02]~/Downloads/FANN-2.2.0-Source$ sudo make install
答案 1 :(得分:1)
在您的情况下,不是编译器,但链接器无法找到该功能。
您满意的编译器包括包含您使用的函数声明的文件,并指定包含文件的目录。
链接器想要查看包含代码编译定义的实际库。
您可能必须在链接器命令行上指定-lfann
(对于在-l
之后使用的确切名称,请参阅实际调用的库 - 如果它被称为libfann.so,请使用以上参数)。
如果库安装在默认目录中,那么这应该足够了;否则你可能还需要-L
参数指向包含库的路径(当然,必须首先编译库)。