Skip to content

Compiling issue #39

Closed
pierre35 opened this Issue Apr 4, 2012 · 4 comments

2 participants

@pierre35
pierre35 commented Apr 4, 2012

Hello,

I have successfully downloaded and compiled flann on ubuntu.

I'm just trying to play with the code to know whether it fits my needs. I'm just recoding a simple version of nlmeans with flann.

however, I cannot compile my code and get the following error:

"pierre@pierre-VirtualBox:~/dev/ContentAwareProcessing$ make
[ 50%] Built target ImageAnalogies
[100%] Building CXX object CMakeFiles/NLMeans.dir/NLMeans.cpp.o
In file included from /home/pierre/third-party/flann-1.7.1-src/build/include/flann/flann.hpp:42:0,
from /home/pierre/dev/ContentAwareProcessing/NLMeans.cpp:12:
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:72:40: error: ‘NNIndex’ is not a template
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h: In function ‘void flann::save_header(FILE*, const NNIndex&)’:
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:80:30: error: invalid use of incomplete type ‘const struct NNIndex’
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:45:7: error: forward declaration of ‘const struct NNIndex’
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:81:24: error: invalid use of incomplete type ‘const struct NNIndex’
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:45:7: error: forward declaration of ‘const struct NNIndex’
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:82:24: error: invalid use of incomplete type ‘const struct NNIndex’
"

Followed by pages of errors. I have tried to look into the error, but cannot find why, since the class NNIndex is obviously defined in nn_index.hpp

Have I missed something obvious?

Thanks, pierre

@mariusmuja
Owner
@pierre35
pierre35 commented Apr 5, 2012

Hello Marius,

Thanks for your prompt answer.

Please find below:
1. the eoor (well, still the same)
2 A simple test code, I just include flann.h without using it in the code
3 My cmakelist. The FindFLANN.cmake rightly locates the include_dir and lib for flann..

Thanks in advance for any hint you may have...
Pierre

1-- error
pierre@pierre-VirtualBox:~/dev/test$ emacs test.cpp
pierre@pierre-VirtualBox:~/dev/test$ make
[100%] Building CXX object CMakeFiles/test.dir/test.cpp.o
In file included from /home/pierre/third-party/flann-1.7.1-src/build/include/flann/flann.hpp:42:0,
from /home/pierre/dev/test/test.cpp:12:
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:72:40: error: ‘NNIndex’ is not a template
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h: In function ‘void flann::save_header(FILE*, const NNIndex&)’:
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:80:30: error: invalid use of incomplete type ‘const struct NNIndex’
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:45:7: error: forward declaration of ‘const struct NNIndex’
/home/pierre/third-party/flann-1.7.1-src/build/include/flann/util/saving.h:81:24: error: invalid use of incomplete type ‘const struct NNIndex’

2- simple source code

#include
#include

#include
#include

// include flann library for approximate search
#include
//#include

//using namespace std;
using namespace flann;

int main ( int argc, char **argv )
{

// input video file /home/pierre/Desktop
std::string image = "/home/pierre/Desktop/image.jpg";

// read image
cv::Mat img = cv::imread(image);

cv::namedWindow ( "Frame",1 );

cv::imshow ( "Frame", img );

while (1)
{
    if ( cv::waitKey ( 30 ) >= 0 ) break;
}


return 0;

}

3- cmakelist

cmake_minimum_required(VERSION 2.8)

This CMakeLists.txt is to be used for compiling

a project outside of vistal project.

Name of your project

PROJECT(Test)

This line will create two variables: MYPROJECT_BINARY_DIR and MYPROJECT_SOURCE_DIR

#Set cmake module path
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/Modules)

#force cmake to look at static libs
#set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

trouver Boost

FIND_PACKAGE(Boost)

find opencv

FIND_PACKAGE(OpenCV REQUIRED)

find flann

FIND_PACKAGE(FLANN REQUIRED)

IF(FLANN_FOUND)
message(STATUS "FLANN FOUND")
message(STATUS ${FLANN_INCLUDE_DIRS})
ENDIF(FLANN_FOUND)

SET(MY_INC "./")
SET(MY_LIB "" )

output directory for executables

#SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/bin")
#SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

4. Compilation

on compile en release par défaut

#SET(CMAKE_BUILD_TYPE Release)

Show to compilator where to look for headers

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} ${FLANN_INCLUDE_DIR} ${MY_INC})

Show where to look for libs

LINK_DIRECTORIES(${MY_LIB} ${LIBRARY_OUTPUT_PATH})

compile exe

ADD_EXECUTABLE(test test.cpp)
TARGET_LINK_LIBRARIES(test ${OpenCV_LIBS} ${Boost_LIBS} ${FLANN_LIBRARIES} boost_program_options)

@mariusmuja
Owner

Hi Pierre,

I replied to this over email a few days ago, but I just noticed it doesn't show up on github, so I'm copying the answer here too:


I believe the problem is that you're mixing OpenCV and FLANN. There was a bug in older versions of OpenCV which caused the FLANN included in OpenCV to be in conflict to the standalone FLANN if used in the same project. This bug should be fixed in the latest version, so if you upgrade your OpenCV installation things should work fine.

Marius

@mariusmuja mariusmuja closed this Apr 9, 2012
@pierre35

Hello Marius,

Well, I thought that was the issue, but I'm using opencv 2.3.1.

I had a 2.1 version installed with synaptic, but removing it didn't help unfortunately. I still have the same error..

i'll look into it more deeply, but it seems that using nanoflann (I think you know this fork) works for me though.

Thanks, pierre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.