2023년 5월 24일 수요일

Windows + vscode + visual studio compiler + c/c++

  1. Extension install



2. Install Visual studio pack


3. Set the VSCode environment settings

3-1. Set the value in the tasks.json file like linked file.

* Please put the  "${workspaceFolder}/*.cpp" in the args to compile c++ files

ref. https://code.visualstudio.com/docs/cpp/config-msvc


4. ctrl + shift + B => Run the tasks!

2021년 10월 4일 월요일

자동 시작프로그램 설정

 

(1)  설정

* 처음에는 해당 위치에 해당 파일이 없는 경우가 일반적이다.

또한 해당 파일이 /etc/rc.local 위치에 있어야 그 부분을 통과한다.

 

1.    $sudo vim /etc/rc.local

#!/bin/bash

 

sudo -H -u yujin /opt/sword/bin/server/http_server start &

     -H sets the HOME environment variable to that of the user.

     -u specifies the username to run as.

     & : run this program as background.

2.    $sudo chmod[1]  +x /etc/rc.local

 

(2)  Background로 돌아가고 있는 프로그램 확인할 수 있는방법

$ ps -eo uid,pid,ppid,stat,comm | grep ${program_name}

(3)  (예외) 로그인 후 프로그램이 동작하길 원함

1.    로그인 후 실행될 파일 만들기

$sudo vim /etc/profile.d/xxx.sh

#!/bin/bash

 

/opt/sword/scripts/run_script/launcher.sh &

2.    Port확인 ( rest / websocket의 경우 뚫려있는지 확인필요)

$ netstat -nap | grep 8080


+x 모드로 간다는 의미 = 모든 사용자에게 실행권한을 준다는 의미

detail : https://eunguru.tistory.com/93

 

이를 숫자로 표현할 때의 의미 : https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means/


1. 실행파일을 rc.local에 등록시켜서 함께 켜지도록 등록하는 방법

2. daemon으로 등록해서 함께 실행하는 방법

2018년 12월 18일 화요일

ROS Errors, Simple Basic C++

image_converter.cpp:1:21: fatal error: ros/ros.h: No such file or directory
compilation terminated.

: rosrun으로 실행 안하고 c++로 실행해서 일어나는 오류!
$ g++ image_converter.cpp 와 같이 실행시 오류발생

[rosrun] Couldn't find executable named image_converter below /home/haei3/catkin_ws/src/image_test

----------------------------------------------------------------------------------------------------------

cvTest.cpp:(.text+0x74): undefined reference to `cv::namedWindow(cv::String const&, int)'
cvTest.cpp:(.text+0x92): undefined reference to `cv::VideoCapture::VideoCapture()'
cvTest.cpp:(.text+0xa6): undefined reference to `cv::VideoCapture::open(int)'
cvTest.cpp:(.text+0xb5): undefined reference to `cv::VideoCapture::isOpened() const'
cvTest.cpp:(.text+0xc2): undefined reference to `cv::VideoCapture::operator>>(cv::Mat&)'
cvTest.cpp:(.text+0x118): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
cvTest.cpp:(.text+0x140): undefined reference to `cv::waitKey(int)'
cvTest.cpp:(.text+0x173): undefined reference to `cv::destroyWindow(cv::String const&)'
cvTest.cpp:(.text+0x196): undefined reference to `cv::VideoCapture::~VideoCapture()'
cvTest.cpp:(.text+0x21b): undefined reference to `cv::VideoCapture::~VideoCapture()'
/tmp/ccJJWQT2.o: In function `cv::String::String(char const*)':
cvTest.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccJJWQT2.o: In function `cv::String::~String()':
cvTest.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccJJWQT2.o: In function `cv::String::operator=(cv::String const&)':
cvTest.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
/tmp/ccJJWQT2.o: In function `cv::Mat::~Mat()':
cvTest.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccJJWQT2.o: In function `cv::Mat::release()':
cvTest.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status

와 같은 오류가 일어나는 이유는, ROS문제가 아니라 OPENCV문제다.

따라서 먼저, 간단한 C++예제가 돌아가는지 확인하자.
<source>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;

int main() {
VideoCapture cap(0);

if (!cap.isOpened())
{
cout << "cannot open camera";
}

//unconditional loop
while (true) {
Mat cameraFrame;
cap.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0) break;
}
return 0;
}
</source>

$  g++ a.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -o openCVtest
: g++라는 프로그램으로/ a.cpp를 실행한다/opencv_core/opencv_highgui/opencv_imgproc/opencv_imgcodecs/opencv_videoio라이브러리를 추가해서/실행파일은 openCVtest라고 이름짓는다.

그래서 Makefile을 쓰는 경우는, LIBRARIES += opencv_core opencv_highgui opencv_imgproc opencv_videoio라고 수정해주란다
(출처 : https://github.com/facebook/C3D/issues/253)