[英]g++ can't find this method even though it's included
I am using FANN ( http://leenissen.dk/fann/wp/download/ ). 我正在使用FANN( http://leenissen.dk/fann/wp/download/ )。 Both headers are available in the archive that you can download there (I hope I don't create too much trouble for you).
这两个标头都可以在存档中找到,您可以在其中下载(我希望我不会给您带来太多麻烦)。
/*
* 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++ says 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)
Can you help me fix this? 你能帮我解决这个问题吗? I think I might have some basic compiler config wrong or something.
我想我可能有一些基本的编译器配置错误或某些错误。
ld
) who can't find the method. ld
)。 -lFANN
) and path to the library there (like -L/path/path/path
. The path you also can specified in $LD_LIBRARY_PATH
system variable, then you don't need -L
option). -lFANN
)和该库的路径(例如-L/path/path/path
。也可以在$LD_LIBRARY_PATH
系统变量中指定该路径,然后您不必需要-L
选项)。 Also you have to install (compile) the library itself before to use it. The guide works for me: 该指南对我有用:
Download the FANN-2.2.0-Source. 下载FANN-2.2.0-源。
Install it with cmake: 用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
In your case, not the Compiler , but the Linker fails to find the function. 在您的情况下,不是Compiler ,但是链接程序无法找到该函数。
The compiler is what you satisfy with including the files containing the declarations of the functions you use, and specifying the directory for the included files. 您对编译器的满意之处在于包括了包含所用函数声明的文件,并指定了所包含文件的目录。
The linker wants to see the actual library containing the compiled definition of the code. 链接器希望查看包含代码编译定义的实际库。
You probably have to specify -lfann
on the linker command line (for the exact name to use after -l
, refer to what the library is actually called - if it is called libfann.so, use above parameter). 您可能必须在链接器命令行上指定
-lfann
(要在-l
之后使用的确切名称,请参阅库的实际名称-如果它被称为libfann.so,请使用上面的参数)。
In case the library is installed in the default directories, thish should be enough; 如果该库安装在默认目录中,则该数目就足够了; otherwise you might also need the
-L
parameter pointing to the path containing the library (and the library would have to be compiled first, of course). 否则,您可能还需要
-L
参数指向包含该库的路径(当然,必须首先编译该库)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.