본문 바로가기

개발로그

ubuntu 18.04 c++ tasks.json 설정

 

[Terminal] - [Configure Default Build Task]  

에서 설정한다.

 

tasks.json 

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "runner": "terminal",
    "tasks": [
        //C++컴파일
        {
            "label": "g++ build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${fileDirname}//**.cpp",
                "-o",
                "${fileDirname}//${fileBasenameNoExtension}.exe"
            ],
            "problemMatcher": ["$gcc"],
            "group": "build"
        },
        //c컴파일
        {
            "label": "gcc build",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g",
                "${fileDirname}\\**.cpp",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "problemMatcher": ["$gcc"],
            "group": "build"
        },
        //실행
        {
            "label": "execute",
            "command": "cmd",
            "group": "test",
            "args": [
                "/C", "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ]
        }
    ]
}

#build

$ cd <project>
$ cmake .
$ make
$ ./<project>

cmakelist

get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME)

string(REPLACE " " "_" ProjectId ${ProjectId})

project(${ProjectId} C CXX)

set (CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 2.8)
find_package( OpenCV REQUIRED )

file(GLOB SOURCES *.cpp)

add_executable(${PROJECT_NAME} ${SOURCES} )
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )