Ask Your Question
0

cannot execute test cpp. Error:line 1: //: Is a directory [closed]

asked 2020-01-27 04:54:38 -0600

andrei186 gravatar image

updated 2020-01-27 04:58:59 -0600

I hope I installed OpenCV on Debian-8 from the Git Repository as prescribed at https://docs.opencv.org/2.4/doc/tutor...

As a result I got the following folders in my home directory:

/home/a/opencv/
/home/a/opencv/build/
/home/a/opencv/build/bin/
/home/a/opencv/samples/
/home/a/opencv/samples/cpp/

As prescribed, I moved to /home/a/opencv/build/bin/ and from there executed the following command:

../../samples/cpp/opencv_version.cpp

opencv_version.cpp is sitting in /home/a/opencv/samples/cpp/

At first I got "Permission denied" although I was logged in as su. This was corrected using chmod u+x opencv_version.cpp

Yet it replies with several errors. The first one being:

line 1: //: Is a directory

Indeed, the 1st line of opencv_version.cp starts with comments // . This indicates that I am doing something fundamentally wrong and even stupid as this is my first encounter with openCV. What is wrong?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by andrei186
close date 2020-03-23 02:14:24.550145

Comments

opencv version ?

berak gravatar imageberak ( 2020-01-27 06:43:40 -0600 )edit
1

opencv version - I have no idea. I installed it as shown at https://docs.opencv.org/2.4/doc/tutor...:

Getting the Cutting-edge OpenCV from the Git Repository¶

Launch Git client and clone OpenCV repository In Linux it can be achieved with the following command in Terminal: cd ~/<my_working _directory=""> git clone https://github.com/opencv/opencv.git</my_working>

It does not say which version. It only says that it is Cutting-edge OpenCV ;) That's why I tried to start using it by executing opencv_version.cpp

andrei186 gravatar imageandrei186 ( 2020-01-27 09:41:49 -0600 )edit

if you use git clone https://github.com/opencv/opencv.git you'll get the master branch (4.2.0-dev as of today) (have to update the answer, then !)

and you did run cmake && make && make install, did you ? ;)

berak gravatar imageberak ( 2020-01-27 10:20:13 -0600 )edit

yes I did PS. My answers keep disappearing so I have to repeat them

andrei186 gravatar imageandrei186 ( 2020-01-27 11:07:13 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2020-01-27 06:47:28 -0600

berak gravatar image

updated 2020-01-27 10:24:27 -0600

you are not supposed to execute any cpp file, you have to compile & link it first.

if you did run make install as the last opencv installation step, you would run a cmdline like

g++ opencv_version.cpp -I /usr/local/include/opencv4 -lopencv_core -o opencv_version

to make an executable binary from your cpp source code, and then run the latter:

./opencv_version

please also look at the cmake example here (as a template to build your own, more complex programs)

edit flag offensive delete link more

Comments

I slightly modified your original command to take into account files locations as follows:

g++ ../samples/cpp/opencv_version.cpp -lopencv_core -o opencv_version

Error:

../samples/cpp/opencv_version.cpp:5:36: fatal error: opencv2/core/utility.hpp: No such file or directory

#include <opencv2 core="" utility.hpp="">

Your modified command

root@debian:/home/a/opencv/build# g++ ../samples/cpp/opencv_version.cpp -I /usr/local/include/opencv4 -lopencv_core -o opencv_version

produced the same result. Also /usr/local/include is empty.

opencv_version.cpp indeed has a line

#include <opencv2/core/utility.hpp>

And there is no core directory in my /home/a/opencv/build/opencv2 directory. It contains only two files cvconfig.h and opencv_modules.hpp

andrei186 gravatar imageandrei186 ( 2020-01-28 02:55:49 -0600 )edit

utility.hpp was found in

/home/a/build/include/opencv4/opencv2/core/utility.hpp
andrei186 gravatar imageandrei186 ( 2020-01-28 03:14:22 -0600 )edit

changed the cpp file to read:

#include </home/a/build/include/opencv4/opencv2/core/utility.hpp>

same error

opencv2/core/utility.hpp: No such file or directory
andrei186 gravatar imageandrei186 ( 2020-01-28 03:31:31 -0600 )edit

please do not try with headers from the src tree, it's not meant to be used like that

you either did not run make install or you pointed CMAKE_INSTALL_PREFIX to some other location than /usr/local

berak gravatar imageberak ( 2020-01-28 03:32:57 -0600 )edit

I did run make install for sure. In case I made a mistake when pointing CMAKE_INSTALL_PREFIX - how can it be corrected now? Shall I run it again?

andrei186 gravatar imageandrei186 ( 2020-01-28 03:42:50 -0600 )edit

run again cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local then cmake && make && make install and g++ ../samples/cpp/opencv_version.cpp -I /usr/local/include/opencv4 -lopencv_core -o opencv_version

Got many screens of errors of type: In file included from /usr/include/c++/4.9/algorithm:61:0, from /usr/local/include/opencv4/opencv2/core/base.hpp:55, from /usr/local/include/opencv4/opencv2/core.hpp:54, from /usr/local/include/opencv4/opencv2/core/utility.hpp:56, from ../samples/cpp/opencv_version.cpp:5: /usr/include/c++/4.9/bits/stl_algobase.h:336:18: note: synthesized method ‘cv::KeyPoint& cv::KeyPoint::operator=(const cv::KeyPoint&)’ first required here *__result = *__first

andrei186 gravatar imageandrei186 ( 2020-01-28 04:38:57 -0600 )edit

/usr/include/c++/4.9/

that means gcc 4.9 ? might be too old / does not have c++11 support out-of-the-box.

try to force it, using

g++ -std=c++11 ...
berak gravatar imageberak ( 2020-01-28 04:54:52 -0600 )edit

root@debian:/home/a/opencv# g++ -std=c++11 g++: fatal error: no input files compilation terminated

andrei186 gravatar imageandrei186 ( 2020-01-28 05:05:41 -0600 )edit

the three dots you put after g++ -std=c++11 - what do they mean? Also does it matter from which directory it should be run? I run it from /home/a/opencv

andrei186 gravatar imageandrei186 ( 2020-01-28 05:09:54 -0600 )edit

nooo, sorry, i meant to add it to yoour cmdline , like:

  g++ -std=c++11 ../samples/cpp/opencv_version.cpp -I /usr/local/include/opencv4 -lopencv_core -o opencv_version
berak gravatar imageberak ( 2020-01-28 05:16:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-27 04:54:38 -0600

Seen: 335 times

Last updated: Jan 27 '20