OpenCV with gcc and CMake: Cannot find source file [closed]

asked 2015-08-23 12:27:04 -0600

Coisadas gravatar image

Hello I installed OpenCV in Fedora 22 using this tutorial.

Now I'm following this example but CMake cannot find source file.

The CMakeLists.txt and DisplayImage.cpp are in the same directory.

[doliveira@localhost OpenCV_tests]$ cmake .
        -- The C compiler identification is GNU 5.1.1
        -- The CXX compiler identification is GNU 5.1.1
        -- Check for working C compiler: /usr/lib64/ccache/cc
        -- Check for working C compiler: /usr/lib64/ccache/cc -- works
        -- Detecting C compiler ABI info
        -- Detecting C compiler ABI info - done
        -- Detecting C compile features
        -- Detecting C compile features - done
        -- Check for working CXX compiler: /usr/lib64/ccache/c++
        -- Check for working CXX compiler: /usr/lib64/ccache/c++ -- works
        -- Detecting CXX compiler ABI info
        -- Detecting CXX compiler ABI info - done
        -- Detecting CXX compile features
        -- Detecting CXX compile features - done
        -- Configuring done
        CMake Error at CMakeLists.txt:5 (add_executable):
              Cannot find source file:
                DisplayImage.cpp
          Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
          .hxx .in .txx
    -- Generating done
    -- Generating done
    -- Build files have been written to: /home/doliveira/Documentos/OpenCV_tests

There is some problem with CMake or OpenCV instalation?

Some info: cmake version 3.2.2 and OpenCV 3.0.0

Thank you

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Coisadas
close date 2015-08-24 06:44:39.227861

Comments

It seems that's not a problem with opencv install but with file DisplayImage.cpp. Are you sure of file name ( uppercase , lowercase)?

LBerger gravatar imageLBerger ( 2015-08-23 13:13:17 -0600 )edit

Yes, the name are the same. I just copied it from the tutorial

My CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
Coisadas gravatar imageCoisadas ( 2015-08-23 15:09:23 -0600 )edit

May be I'm wrong but I still think your filename is wrong not your CMakefLists.txt. you can try like this

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )

file(GLOB DisplayImage_SRCS
    "*.h"
    "*.cpp")

ADD_EXECUTABLE (DisplayImage ${DisplayImage_SRCS})

include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
LBerger gravatar imageLBerger ( 2015-08-23 15:27:26 -0600 )edit

I changed the CMakeLists.txt with your code and there is the result:

CMake Error at CMakeLists.txt:9 (ADD_EXECUTABLE):
  add_executable called with incorrect number of arguments

CMake Error at CMakeLists.txt:12 (target_link_libraries):
  Cannot specify link libraries for target "DisplayImage" which is not built
  by this project.

-- Configuring incomplete, errors occurred!

What's that meaning?

The folder where I execute cmake . is that

[doliveira@localhost OpenCV_tests]$ ll
total 8
-rwxrwxr-x. 1 doliveira doliveira 239 Ago 23 22:10 CMakeLists.txt
-rwxrwxr-x. 1 doliveira doliveira 478 Ago 23 11:57 DisplayImage.cpp 
[doliveira@localhost OpenCV_tests]$
Coisadas gravatar imageCoisadas ( 2015-08-23 16:09:03 -0600 )edit

It means that cmake cannot find any source file in folder. You're using linux and called cmake from a terminal I think. So simple way is :

cd folder_where source files and CMakeLists.txt are
cmake

So nowmay be I'm wrong your name file is good but CMakeLists.txt is not in same directory than sourcefile or you don't call cmake from directory where are CMakeLists.txt and DisplayImage.cpp

LBerger gravatar imageLBerger ( 2015-08-23 16:21:22 -0600 )edit

I call cmake in the same directory where are CMakeLists.txt and DisplayImage.cpp.

[doliveira@localhost OpenCV_tests]$ ll
total 8
-rwxrwxr-x. 1 doliveira doliveira 239 Ago 23 22:11 CMakeLists.txt
-rwxrwxr-x. 1 doliveira doliveira 478 Ago 23 11:57 DisplayImage.cpp 
[doliveira@localhost OpenCV_tests]$ cmake .
CMake Error at CMakeLists.txt:5 (add_executable):
  Cannot find source file:

    DisplayImage.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

-- Generating done
-- Build files have been written to: /home/doliveira/Documentos/OpenCV_tests

How can I sprecifie the directory of DisplayImage.cpp in the CMakeLists.txt?

It's really weird.

Coisadas gravatar imageCoisadas ( 2015-08-23 16:44:59 -0600 )edit
1

yes it's possible go to cmake site. But you can specify source_dir in command line

cmake-D CMAKE_SOURCE_DIR="/home/doliveira/Documentos/OpenCV_tests" -D CMAKE_BINARY_DIR="/home/doliveira/Documentos/OpenCV_tests/bin"

Now I still think you've got problem with file name. Have you copy cmakelist from web? May be you've got some invisible character. When I select this line

-rwxrwxr-x. 1 doliveira doliveira 478 Ago 23 11:57 DisplayImage.cpp

I have got a white character after cpp Try to rename DisplayImage.cpp in Displayimage.cc...

LBerger gravatar imageLBerger ( 2015-08-23 17:06:41 -0600 )edit

The problem was the name!

The white character after the .cpp.

I will never see that detail.

Thank you @LBerger for your time!

Coisadas gravatar imageCoisadas ( 2015-08-23 17:15:53 -0600 )edit

@sturkmen Yes, I did but didn't work to

Coisadas gravatar imageCoisadas ( 2015-08-23 17:28:39 -0600 )edit

ok. anyhow you got solution i think. while i was writing my comment you post stating the problem was about filename.

sturkmen gravatar imagesturkmen ( 2015-08-23 17:33:42 -0600 )edit