본문 바로가기
전체보기/OpenCV

Linux OpenCV g++ Compile

by 피망우유 2020. 5. 31.
$ g++ filename.cpp $(pkg-config --cflags --libs opencv)

 

CMakeLists.txt

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(PROJECT_NAME)

find_package(OpenCV REQUIRED)

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(PROJECT_NAME main.cpp)

# Link your application with OpenCV libraries
target_link_libraries(PROJECT_NAME ${OpenCV_LIBS})

 

 

CMakeLists.txt 동적 라이브러리와 함께 사용할 때

(경로 지정 생략하고 쓸 때)

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(PROJECT_NAME)

find_package(OpenCV REQUIRED)

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(PROJECT_NAME main.cpp)

# Link your application with OpenCV libraries
target_link_libraries(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR}/lib.so ${OpenCV_LIBS})

${절대경로}/동적라이브러리경로

target_link_libraries(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR}/lib.so ${OpenCV_LIBS})

 

fn.cpp과  fn.h 파일이 있을 때 (main 없음)

동적 라이브러리 생성

$ g++ -fPIC -c fn.cpp $(pkg-config --cflags --libs opencv)

$ g++ -shared -o libfn.so fn.o

 

정적 라이브러리 생성

$ g++ -fPIC -c fn.cpp $(pkg-config --cflags --libs opencv)

$ ar rscv libfn.a fn.o

'전체보기 > OpenCV' 카테고리의 다른 글

Raspberry Pi OpenCV 3.2 설치  (0) 2020.05.31
워핑(warping) 기법  (0) 2019.11.14
OpenCV 설정 + findContours 에러 + extra 모듈 설정  (0) 2019.11.14

댓글