dynamic library creation when installing with Cmake - c++

I've been trying to install a package called DAKOTA, which employs BOOST and Trilinos libraries which I'm already using in another program. For compiling and linking I'm using cmake, but I have not been able to pass the make step. It would be very helpful perhaps if you could point me out into some direction. Please find below the cmake command script I'm using to compile and link the libraries, and the process when it stops...
As far as I have understood is the following. I'm using Boost and Trilinos library files used to build the other program to built the project DAKOTA. But I get an error when creating the library file liboptpp.so from Teuchos_BLAS.cpp.o, because it-s being used by libteuchosnumerics.a. I'm not sure if I'm understanding it correctly, but what I got from this is that I need to create a shared library and recompile the Teuchos_BLAS.cpp.o again using -fPIC.
I tried including -fPIC in CMAKE_CXX_FLAGS as you may see below, and also -shared in CMAKE_SHARED_LINKER_FLAGS but this doesn't seem to work. In the past I also tried adding -fPIC in all flags from the CMakeCache.txt but also did not work.
Please let me know your understanding and suggestions.
Thank you very much in advance,
CMAKE COMMAND
! /bin/bash
cmake \
-D CMAKE_INSTALL_PREFIX=/home/pablo/BuildDakota/build \
-D MPI_BASE_DIR:PATH="/usr/lib/openmpi/" \
-D CMAKE_CXX_FLAGS:STRING="-O0 -std=c++11 -pedantic -ftrapv -Wall -fPIC -Wno-long-long" \
-D BOOST_ROOT:PATH=/home/pablo/BuildPeridigm/ \
-D Boost_NO_BOOST_CMAKE:BOOL=TRUE \
-D Boost_NO_SYSTEM_PATHS:BOOL=TRUE \
-D Trilinos_DIR:PATH=/home/pablo/BuildPeridigm/lib/cmake/Trilinos/ \
-D CMAKE_SHARED_LINKER_FLAGS:STRING="-shared" \
/home/pablo/BuildDakota/dakota-6.7.0.src
PROCESS
[ 9%] Building C object packages/external/OPTPP/src/CMakeFiles/optpp.dir/PDS/sort.c.o
[ 9%] Building C object packages/external/OPTPP/src/CMakeFiles/optpp.dir/PDS/writes.c.o
[ 10%] Building CXX object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/BoolVector.C.o
[ 10%] Building C object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/file_cutils.c.o
[ 10%] Building CXX object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/ioformat.C.o
[ 10%] Building CXX object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/mcholesky.C.o
[ 10%] Building CXX object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/OptppExceptions.C.o
[ 10%] Building CXX object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/OptppFatalError.C.o
[ 10%] Building CXX object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/print.C.o
[ 10%] Building C object packages/external/OPTPP/src/CMakeFiles/optpp.dir/Utils/timers.c.o
[ 10%] Linking CXX shared library ../lib/liboptpp.so
/usr/bin/ld: /home/pablo/BuildPeridigm/lib/libteuchosnumerics.a(Teuchos_BLAS.cpp.o): relocation R_X86_64_32S against `_ZN7Teuchos11ETranspCharE' can not be used when making a shared object; recompile with -fPIC
/home/pablo/BuildPeridigm/lib/libteuchosnumerics.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
packages/external/OPTPP/src/CMakeFiles/optpp.dir/build.make:2264: recipe for target 'packages/external/OPTPP/lib/liboptpp.so' failed
make[2]: *** [packages/external/OPTPP/lib/liboptpp.so] Error 1
CMakeFiles/Makefile2:1409: recipe for target 'packages/external/OPTPP/src/CMakeFiles/optpp.dir/all' failed
make[1]: *** [packages/external/OPTPP/src/CMakeFiles/optpp.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

I tried including -fPIC in CMAKE_CXX_FLAGS as you may see below, and
also -shared in CMAKE_SHARED_LINKER_FLAGS but this doesn't seem to
work.
Don't do this. Adding low-level compiler flags manually is almost always a bad idea in CMake.
The general approach to request a project to build as a dynamic library is to set the BUILD_SHARED_LIBS option of the project:
cmake -DBUILD_SHARED_LIBS=ON [...]
If this doesn't work right away, it usually means that the project was not intended to be built as a dynamic library, in which case there is no easy solution.
Dakota, for instance, claims to support this option properly.
If this doesn't work, you can try playing around with options like CMAKE_POSITION_INDEPENDENT_CODE, but your chances of success will not be very high. You should probably contact the library maintainer for advice in this case.

Related

CMake issues with target_include directories

I'm working on a new project, and trying to set up cmake from the ground up for the first time. I have two libraries that get built as targets in my project; libnet and liberror. I am linking libnet with liberror when I build the libnet target, and want to be able to #include header files that exist within liberror. I have the following added to the CMakeLists.txt for liberror:
target_include_directories(liberror SYSTEM PUBLIC core/error)
Now, I have the following added to the CMakeLists.txt for libnet:
target_link_libraries(libnet
PUBLIC
liberror)
So, liberror provides a header called ExceptionBuilder.hpp. When I try to do the following from libnet:
#include <core/error/ExceptionBuilder.hpp>
I get this error:
fatal error: core/error/ExceptionBuilder.hpp: No such file or directory
3 | #include <core/error/ExceptionBuilder.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I am quite new to cmake, so probably just setting something up incorrectly here, but any ideas? Here is the project structure:
Project Structure
Here is the verbose build output:
nmcurtis#DESKTOP-JC26375:~/distro/build$ make
-- Boost version: 1.58.0
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nmcurtis/distro/build
Consolidate compiler generated dependencies of target distro_core_error_objects
[ 11%] Built target distro_core_error_objects
Consolidate compiler generated dependencies of target distro_core_utility_objects
[ 16%] Built target distro_core_utility_objects
[ 22%] Linking CXX shared library libdistro_core_utility.so
/usr/local/gcc-11.3.0/bin/g++-11.3 -fPIC -fPIC -Wno-terminate -shared -Wl,-soname,libdistro_core_utility.so -o libdistro_core_utility.so CMakeFiles/distro_core_utility_objects.dir/Concepts.cpp.o
[ 22%] Built target distro_core_utility
[ 27%] Linking CXX shared library libdistro_core_error.so
/usr/local/gcc-11.3.0/bin/g++-11.3 -fPIC -fPIC -Wno-terminate -shared -Wl,-soname,libdistro_core_error.so -o libdistro_core_error.so CMakeFiles/distro_core_error_objects.dir/Exception.cpp.o CMakeFiles/distro_core_error_objects.dir/ExceptionBuilder.cpp.o -Wl,-rpath,/home/nmcurtis/distro/build/core/utility: ../utility/libdistro_core_utility.so
[ 27%] Built target distro_core_error
[ 33%] Linking CXX static library libdistro_core_utility_static.a
/usr/bin/ar qc libdistro_core_utility_static.a CMakeFiles/distro_core_utility_objects.dir/Concepts.cpp.o
/usr/bin/ranlib libdistro_core_utility_static.a
[ 33%] Built target distro_core_utility_static
[ 38%] Linking CXX static library libdistro_core_error_static.a
/usr/bin/ar qc libdistro_core_error_static.a CMakeFiles/distro_core_error_objects.dir/Exception.cpp.o CMakeFiles/distro_core_error_objects.dir/ExceptionBuilder.cpp.o
/usr/bin/ranlib libdistro_core_error_static.a
[ 38%] Built target distro_core_error_static
Consolidate compiler generated dependencies of target distro_core_net_objects
[ 44%] Building CXX object core/net/CMakeFiles/distro_core_net_objects.dir/Address.cpp.o
/home/nmcurtis/distro/core/net/Address.cpp:4:10: fatal error: core/error/ExceptionBuilder.hpp: No such file or directory
4 | #include <core/error/ExceptionBuilder.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
core/net/CMakeFiles/distro_core_net_objects.dir/build.make:120: recipe for target 'core/net/CMakeFiles/distro_core_net_objects.dir/Address.cpp.o' failed
make[2]: *** [core/net/CMakeFiles/distro_core_net_objects.dir/Address.cpp.o] Error 1
CMakeFiles/Makefile2:262: recipe for target 'core/net/CMakeFiles/distro_core_net_objects.dir/all' failed
make[1]: *** [core/net/CMakeFiles/distro_core_net_objects.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
nmcurtis#DESKTOP-JC26375:~/distro/build$
If you do target_include_directories(liberror SYSTEM PUBLIC core/error) you do not need core/error in #include <core/error/ExceptionBuilder.hpp>
Do this in core/error/CMakeLists.txt.
target_include_directories(liberror SYSTEM PUBLIC .)
# or
# target_include_directories(liberror SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
#include "ExceptionBuilder.hpp"
If you wish #include "core/error/ExceptionBuilder.hpp" then
do this in core/error/CMakeLists.txt.
target_include_directories(liberror SYSTEM PUBLIC ../..)
# or
# target_include_directories(liberror SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../..)

CMake linker cannot find library that does not begin with "lib"

I am using CMake to compile an application which uses the HSImage library on github. After installing with pip, the HSI library generates a shared library file, in my case it is created at /usr/src/HSI/HSI.cpython-36m-aarch64-linux-gnu.so
I am trying to link this library to my application with CMake, but the CMake find_library method is having some trouble finding the library. Here is the relevant part of my CMakeLists.txt file:
CMakeLists.txt
set(HSI_DIR /usr/src/HSI)
find_library(HSI_LIB HSI.cpython-36m-aarch64-linux-gnu PATHS ${HSI_DIR})
message(STATUS "HSI: ${HSI_LIB}") # outputs /usr/src/HSI/HSI.cpython-36m-aarch64-linux-gnu.so
add_executable(${TARGET_NAME} <sources...>)
target_link_directories(${TARGET_NAME} PUBLIC ${HSI_DIR})
target_link_libraries(${TARGET_NAME}
${HSI_LIB}
<other libs...>
-Wl,--unresolved-symbols=ignore-in-shared-libs
)
When building, this produces the following error message:
cd /home/nvidia/projects/HsiInference/build;/usr/local/bin/cmake --build "/home/nvidia/projects/HsiInference/build" --target hsi_inference_onnx -- ;
Scanning dependencies of target hsi_inference_onnx
[ 14%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/targets/HsiInferenceOnnx/main_onnx.cpp.o
[ 28%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/targets/HsiInferenceOnnx/HsiInferenceOnnx.cpp.o
[ 42%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/ftpnano.cpp.o
[ 57%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/getOptions.cpp.o
[ 71%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/logger.cpp.o
[ 85%] Building CXX object CMakeFiles/hsi_inference_onnx.dir/src/utils.cpp.o
[100%] Linking CXX executable hsi_inference_onnx_debug
CMakeFiles/hsi_inference_onnx.dir/build.make:245: recipe for target 'hsi_inference_onnx_debug' failed
CMakeFiles/Makefile2:123: recipe for target 'CMakeFiles/hsi_inference_onnx.dir/all' failed
**/usr/bin/ld: cannot find -lHSI.cpython-36m-aarch64-linux-gnu**
**collect2: error: ld returned 1 exit status**
make[3]: *** [hsi_inference_onnx_debug] Error 1
make[2]: *** [CMakeFiles/hsi_inference_onnx.dir/all] Error 2
CMakeFiles/Makefile2:130: recipe for target 'CMakeFiles/hsi_inference_onnx.dir/rule' failed
make[1]: *** [CMakeFiles/hsi_inference_onnx.dir/rule] Error 2
Makefile:196: recipe for target 'hsi_inference_onnx' failed
make: *** [hsi_inference_onnx] Error 2
Build failed.
The important part:
/usr/bin/ld: cannot find -lHSI.cpython-36m-aarch64-linux-gnu
collect2: error: ld returned 1 exit status
From what I have gathered, target_link_libraries simply adds -l<library_name> to the link command, and -l<library_name> assumes that there is a file called lib<library_name>.so to link, which is not the case here. How can I get CMake to link the library properly despite the weird filename?
NOTE:
I am able to get the project to build by doing the following:
Delete the project's build directory to clear CMake caches
Rename the file or create a symbolic link to libhsi.so
Change CMakeLists.txt to find_library(HSI_LIB hsi PATHS ${HSI_DIR})
This changes the link command to -lhsi instead, which is able to find the renamed/soft-linked library file. HOWEVER, this is not ideal for me and the original question remains unanswered :)
For libraries with weird filename you should add : before the filename. Be careful, like mentioned in https://linux.die.net/man/1/ld : If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a (namespec is what comes after -l).
For your example you should replace ${HSI_LIB} in target_link_libraries by :${HSI_LIB}.so.

Cannot find lpublic library

Trying to compile my project on Centos 8.2 using cmake 3.12, im facing with the following error:
cannot find -lpublic
here is full log:
[ 20%] Building CXX object CMakeFiles/ .cpp.o
[ 40%] Building CXX object CMakeFiles/ .cpp.o
[ 60%] Linking CXX shared library .so
[ 60%] Built target myproj
Scanning dependencies of target nist01
[ 80%] Building CXX object CMakeFiles/ .cpp.o
[100%] Linking CXX executable
/usr/bin/ld: cannot find -lpublic
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/nist01.dir/build.make:85: ...] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/...] Error 2
make: *** [Makefile:84: all] Error 2
Tried to find something on the internet, but nothing shown up.
Thanks for your help.
That seems like you try to link against the target "public", which is a suspicious target name. It might be target_link_libraries command with lowercase public instead of uppercase one, like target_link_libraryies(nist01 public something) instead of target_link_libraries(nist01 PUBLIC something).

Cannot build opencv 2.4 on a 64 bit mac for C++ project in Xcode

After looking around a lot and trying every option I found on SO, I'm a little confused about how to get the OpenCV library for architecture x86_64 loaded on my Mac. Here's a little bit of background info:
The first folder contains the Android SDK. The second is the iPhone framework, which uses i386 and armv7 architectures.
Now, I want to create a simple "Hello World" C++ application in Xcode which needs the correct library for x86_64 architecture.
I've looked at this tutorial as well as others' posted steps as follows:
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make -j8
sudo make install
With all version (except OpenCV-2.4.6.1), the process fails at "make -j8". I get the same error every time:
Linking CXX shared library ../../lib/libopencv_core.dylib
Undefined symbols for architecture x86_64:
"___sincos_stret", referenced from:
cv::RotatedRect::points(cv::Point_<float>*) const in matrix.cpp.o
cv::RotatedRect::boundingRect() const in matrix.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_core.2.4.3.dylib] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfThreading.cpp.o
[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTileDescriptionAttribute.cpp.o
[ 28%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledInputFile.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledMisc.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledOutputFile.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTiledRgbaFile.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTileOffsets.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTimeCode.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfTimeCodeAttribute.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfVecAttribute.cpp.o
[ 29%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfVersion.cpp.o
[ 29%] [ 30%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfWav.cpp.o
Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfZipCompressor.cpp.o
Linking CXX static library ../lib/libIlmImf.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadMutex.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphore.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphorePosixCompat.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadMutex.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphore.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../lib/libIlmImf.a(IlmThreadSemaphorePosixCompat.cpp.o) has no symbols
[ 30%] Built target IlmImf
make: *** [all] Error 2
pdls-mbp:build pdl$
With OpenCV-2.4.6.1, the process fails at "sudo make install" and I get the following error:
Linking CXX shared library ../../lib/libopencv_core.dylib
Undefined symbols for architecture x86_64:
"___sincos_stret", referenced from:
cv::RotatedRect::points(cv::Point_<float>*) const in matrix.cpp.o
cv::RotatedRect::boundingRect() const in matrix.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libopencv_core.2.4.6.dylib] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [all] Error 2
Lucys-MacBook-Pro:build pdl$
When I installed OpenCV using Homebrew, opencv was installed in use/local/opt/opencv and I can see all of the dylib files under the lib folder:
All of this completely confuses me, because I think all I need is a .a library file, no?
I have found the dylib files that were installed with HomeBrew in /usr/local/Cellar/opencv/2.4.6.1/lib but when I try to choose frameworks and libraries to add, they do not show up in the list. Instead, this is all I see:
Aldo, been following this MacPorts tutorial.
Have you considered using macports? It has opencv 2.4.8 available.
So after installing macports, all that nonsense you've been through, is reduced to:
$ sudo port selfupdate
$ sudo port install opencv
if you want a variant or two, for example OpenCL and Python support, then that would be:
$ sudo port install opencv +opencl +python27
and the binaries/libraries/whatever will be installed into /opt/local/....

g++ can't find this method even though it's included

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++ says
"/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.
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).
This is the linker (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 here.
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
In your case, not the Compiler, but the Linker 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.
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).
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).