g++ no puede encontrar este método a pesar de que está incluido
Frecuentes
Visto 431 veces
0
I am using 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 ++ dice
"/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.
2 Respuestas
2
- The compiler has compiled your code. The includes are really work. (But you don't have to specify full path there, just the name of the header, if the library is installed correctly).
- Este es el enlazador (
ld
) who can't find the method. - The linker problems about whether you have library with the method definition and give it to the linker (in its options) when you call it.
- You use make file, so you have to specify options (something like
-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). Also you have to install (compile) the library itself before to use it. You have installation guide aquí.
The guide works for me:
Download the FANN-2.2.0-Source.
Install it with 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
respondido 27 nov., 13:07
@SimonKuang, what you did exactly? It works for me (see the answer). - klm123
Alright. I got CMake to work and I sudo make install
ed it: everything worked. How do I change my code now? (and/or my linker stuff) - Simón Kuang
@SimonKuang, have you checked examples like mentioned in "When all else fails"?? You have Makefile example there. The key option I think is -lfann. - klm123
Yes. That was the example in my question, except the C++ version. - Simón Kuang
I have installed everything I ought to. How should I change my code now? Apparently the "when all else fails" does not work. - Simón Kuang
1
In your case, not the Compilador, Pero el enlaces fails to find the function.
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.
Probablemente tengas que especificar -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).
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).
respondido 27 nov., 13:07
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c++ installation g++ makefile linker-errors or haz tu propia pregunta.
¿Dónde está
fann_get_user_data
and the other listed functions suppose to be? If they're part of an external library you probably have to link it in which I don't see you doing in the link command. - greatwolfIt's the linker that is complaining You need to link to the library. - Duck
Did you build and install the library using CMake? After doing this, add required FANN libraries to your project makefile. - Alex F
@Duck How? FANN only told me to include those two files. - Simon Kuang
@AlexFarber How? The header comments say that I only have to include those like that. Can you tell me how to do the CMake thing, or link to a guide? - Simon Kuang