C++ executable file not build

i am new to ROS currently working on ROS Kinetic,i have an issue when i run this linefollowing.cpp file using the command “rosrun roscv linefollowing.cpp” (where roscv is the package name & “linefollowing.cpp” is the .cpp file),

the error;

/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 19: using: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 20: using: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 21: namespace: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 22: static: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 24: float: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 25: float: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 26: float: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 28: class: command not found
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 36: syntax error near unexpected token `('
/home/badhrisrini/line_follow_ws/src/roscv/src/linefollow.cpp: line 36: `  image_transport::Publisher image_pub_; //image publisher(we subscribe to ardrone image_raw)'

the code in this file is;

#include <ros/ros.h>
#include <stdio.h>
#include <iostream>
#include "std_msgs/String.h"
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>     //make sure to include the relevant headerfiles
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <cv_bridge/CvBridge.h>
#include <cvaux.h>
#include<math.h>
#include <cxcore.h>
#include "turtlesim/Velocity.h"
     
/*here is a simple program which demonstrates the use of ros and opencv to do image manipulations on video streams given out as image topics from the monocular vision
of robots,here the device used is a ardrone(quad-rotor).*/
using namespace std;
using namespace cv;
namespace enc = sensor_msgs::image_encodings;
static const char WINDOW[] = "Image window";
     
float prevVelocity_angular ,prevVelocity_linear ,newVelocity_angular ,newVelocity_linear ;
float derive_angular, derive_linear, dt = 0.5;
float horizontalcount;
     
class ImageConverter
{
  ros::NodeHandle nh_;
  ros::NodeHandle n;
  ros::Publisher pub ;
  ros::Publisher tog;
  image_transport::ImageTransport it_;    
  image_transport::Subscriber image_sub_; //image subscriber 
  image_transport::Publisher image_pub_; //image publisher(we subscribe to ardrone image_raw)
  std_msgs::String msg;
public:
  ImageConverter()
    : it_(nh_)
  {
      pub= n.advertise<turtlesim::Velocity>("/drocanny/vanishing_points", 500);//
      image_sub_ = it_.subscribe("/ardrone/image_raw", 1, &ImageConverter::imageCb, this);
      image_pub_= it_.advertise("/arcv/Image",1);    
  }
     
  ~ImageConverter()
  {
    cv::destroyWindow(WINDOW);
  }
     
  void imageCb(const sensor_msgs::ImageConstPtr& msg)
  {
     
     sensor_msgs::CvBridge bridge;//we need this object bridge for facilitating conversion from ros-img to opencv
   IplImage* img = bridge.imgMsgToCv(msg,"rgb8");  //image being converted from ros to opencv using cvbridge
   turtlesim::Velocity velMsg;
 CvMemStorage* storage = cvCreateMemStorage(0);
     CvSeq* lines = 0;
       int i,c,d;
       float c1[50]; 
       float m,angle;
          float buf;
          float m1;
       float dis;
       int k=0,k1=0; 
      int count=0;  
     
      float xv;
      float yv;
      int vc=0;
     float xvan=0,yvan=0;
      static float xvan1=0,yvan1=0;
    float num=0;
   static float count1=0;
  float dv;
float vxx,vyy;
     
         cvSetImageROI(img, cvRect(0, 0,170, 140));
        IplImage* out1 = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );   //make sure to feed the image(img) data to the parameters necessary for canny edge output 
        IplImage* gray_out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 ); 
        IplImage* canny_out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );
        IplImage* gray_out1=cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
          IplImage* canny_out1 = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );
          IplImage* canny_out2 = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );
     
        cvSmooth( img, out1, CV_GAUSSIAN, 11, 11 );
     
      cvCvtColor(out1 , gray_out, CV_RGB2GRAY);
        cvCanny( gray_out, canny_out, 50, 125, 3 );
      cvCvtColor(canny_out ,gray_out1, CV_GRAY2BGR);
     
     
     
       lines = cvHoughLines2( canny_out, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80,50, 10 );
        for( i = 0; i < lines->total; i++ )
        {    
     
             CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
{           
{
cvLine( out1, line[0], line[1], CV_RGB(0,255,0), 1, 8 );
cvLine( gray_out1, line[0], line[1], CV_RGB(0,255,0), 2, 8 );
xv=line[0].x-line[1].x;
yv=line[0].y-line[1].y;
velMsg.linear = atan2(xv,yv)*180 /3.14159265;
angle=velMsg.linear;
if(velMsg.linear<-90)
{
  velMsg.linear=velMsg.linear+180;
}
buf=(line[0].x+line[1].x)/2;
     
if(abs(85-buf)<=15)
{
velMsg.angular =0;
}
else
{
velMsg.angular =(85-(line[0].x+line[1].x)/2);
}
     
if(abs(velMsg.angular)>50)
{
velMsg.angular =0;
}
     
     
     
     
     
printf("\nX::Y::X1::Y1::%d:%d:%d:%d",line[0].x,line[0].y,line[1].x,line[1].y);
     
pub.publish(velMsg);
     
     
} 
     
     
     
}
     
cvSeqRemove(lines,i);
     
{
         cvShowImage( "OUT1", out1 );//lines projected onto the real picture
        cvShowImage( "GRAY_OUT1", gray_out1 );
        cv::waitKey(3);
   sensor_msgs::ImagePtr out = sensor_msgs::CvBridge::cvToImgMsg(img, "rgb8");//image converted from opencv to ros for publishing
   image_pub_.publish(out);
 cvClearMemStorage(storage);
cvReleaseMemStorage(&storage);
}
     
};
     
int main(int argc, char** argv)
{
  ros::init(argc, argv, "image_converter");
  ImageConverter ic;
  ros::spin();
  return 0;
}

CMakeLists.txt of the package “roscv” ;

cmake_minimum_required(VERSION 3.0.2)
project(roscv)
find_package(catkin REQUIRED COMPONENTS
  ardrone_autonomy
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  std_msgs
  std_srvs
  turtlesim
)
find_package(OpenCV)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
include_directories(${OpenCV_INCLUDE_DIRS})




catkin_package(
    CATKIN_DEPENDS
     ardrone_autonomy
     cv_bridge
     image_transport
     roscpp
     sensor_msgs
     std_msgs
     std_srvs
     turtlesim
)


catkin_package(
INCLUDE_DIRS include
LIBRARIES roscv
CATKIN_DEPENDS ardrone_autonomy cv_bridge image_transport opencv2 roscpp sensor_msgs std_msgs std_srvs turtlesim
DEPENDS system_lib
)

add_executable(linefollowing src/linefollowing.cpp)

target_link_libraries(linefollowing ${catkin_LIBRARIES})
install(TARGETS linefollowing
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

i am aware that we cannot run a .cpp file in ros instead we have to run the ros executable file which will be build after building the package. but the issue is the after i run “cmake .” in the package directory and “catkin_make” in the workspace directory i can’t find the executable file which should have been created!
To be exact i am working on a line following drone using ARdrone 2.0 , openCV and a sliding mode controller. does Construct have any related course to this which can be helpful for this project (note: iam working on ubuntu 16.04(kinetic) and 18.04(melodic) versions not working in ROS Development studio). Any suggestions for the above issue and on my project?? thank you in advance!!

Please try running

rosrun roscv linefollowing

You won’t find the C++ executable within your workspace - it would be somewhere in the build/devel folders, but you don’t need to worry about where it’s.

This line in your CMakeLists.txt file defines the name of the executable:

add_executable(linefollowing src/linefollowing.cpp)

so if catkin_make ran successfully it should be available.

I see that you have not taken the ROS basics course but you have been taking the OpenCV course. Please take one of the following basics course first (if you are not familiar with C++ it might be better to take the Python version of the course as it’s easier for beginners to programming):

hello there, thanks for the reply!! i tried the command and still the says the same!

[rosrun] Couldn’t find executable named linefollowing below /home/badhrisrini/line_follow_ws/src/roscv

but i have noticed one thing in “catkin_make” that it builds every target needed(including “ardrone_driver” but it does not say “built target linfollowing” anywhere in the catkin_make’s process! so i have pasted down the whole catkin_make process down here!

badhrisrini@badhrisrini-Inspiron-3585:~/line_follow_ws$ catkin_make
Base path: /home/badhrisrini/line_follow_ws
Source space: /home/badhrisrini/line_follow_ws/src
Build space: /home/badhrisrini/line_follow_ws/build
Devel space: /home/badhrisrini/line_follow_ws/devel
Install space: /home/badhrisrini/line_follow_ws/install

Running command: “make cmake_check_build_system” in “/home/badhrisrini/line_follow_ws/build”

Running command: “make -j8 -l8” in “/home/badhrisrini/line_follow_ws/build”

[ 1%] Performing update step for ‘ardronelib’
[ 1%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_pressure_raw
[ 2%] Performing configure step for ‘ardronelib’
No configure
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_CamSelect
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_time
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_RecordEnable
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_watchdog
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_demo
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_vision_raw
[ 2%] Performing build step for ‘ardronelib’
make[3]: warning: jobserver unavailable: using -j1. Add ‘+’ to parent make rule.
[ 2%] Built target std_msgs_generate_messages_nodejs
Libs already extracted
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_magneto
Building target static
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_video_stream
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_hdvideo_stream
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_kalman_pressure
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_wind_speed
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_vision_perf
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_Navdata
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_FlightAnim
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_LedAnim
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_gyros_offsets
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_references
Architecture x86_64 is already built
Creating universal static lib file from architectures x86_64
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_trims
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_phys_measures
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_trackers_send
Build done.
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_raw_measures
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_pwm
Building ARDroneTool/Lib
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_vision_detect
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_vector31
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_altitude
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_vector21
[ 2%] Built target geometry_msgs_generate_messages_nodejs
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_rc_references
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_matrix33
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_wifi
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_games
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_adc_data_frame
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_vision_of
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_euler_angles
[ 2%] Built target std_msgs_generate_messages_py
[ 2%] Built target std_msgs_generate_messages_cpp
[ 2%] Built target geometry_msgs_generate_messages_py
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_zimmu_3000
[ 2%] Built target geometry_msgs_generate_messages_cpp
[ 2%] Built target std_msgs_generate_messages_eus
[ 2%] Built target geometry_msgs_generate_messages_lisp
[ 2%] Built target geometry_msgs_generate_messages_eus
[ 2%] Built target std_msgs_generate_messages_lisp
[ 2%] Built target _ardrone_autonomy_generate_messages_check_deps_navdata_vision
[ 20%] Built target ardrone_autonomy_generate_messages_lisp
[ 39%] Built target ardrone_autonomy_generate_messages_eus
[ 76%] Built target ardrone_autonomy_generate_messages_nodejs
[ 77%] Built target ardrone_autonomy_generate_messages_py
[ 95%] Built target ardrone_autonomy_generate_messages_cpp
[ 95%] Built target ardrone_autonomy_gencpp
[ 95%] Built target ardrone_autonomy_generate_messages
Building ARDroneTool/Lib
[ 95%] Performing install step for ‘ardronelib’
make[3]: warning: jobserver unavailable: using -j1. Add ‘+’ to parent make rule.
[ 96%] Completed ‘ardronelib’
[ 97%] Built target ardronelib
[100%] Built target ardrone_driver

If the executable is not built then it means some has not been properly done:

  • You should have created the package with catkin_create_pkg.
  • You should edit CMakeLists.txt and package.xml as described in the ROS Basics course.

Also, before you rerun catkin_make any time, do:

cd ~/catkin_ws
rm -rf build/ devel/

This topic was automatically closed after 19 hours. New replies are no longer allowed.