시작하기 전에 다음 도구가 설치되어 있어야 한다.
git clone https://github.com/Microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
vcpkg install POCO
기본적으로 x86 라이브러리가 설치된다. x64용을 설치하려면 다음 명령줄 처럼 사용한다.
vcpkg install [package name]:x64-windows
외부 IDE 에서 CMake와 함께 vcpkg를 사용하려면 툴체인 파일을 사용한다. 툴체인 파일 경로를 CMAKE_TOOLCHAIN_FILE
변수에 설정한다.
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(helloworld LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# this is heuristically generated, and may not be correct
find_package(Poco CONFIG REQUIRED Net XML Zip Data Util)
add_executable(helloworld
main.cpp
)
target_link_libraries(helloworld PRIVATE Poco::Net Poco::XML Poco::Zip Poco::Data Poco::Util)
main.cpp
#include "Poco/DirectoryWatcher.h"
#include "Poco/Delegate.h"
#include "Poco/FileStream.h"
#include "Poco/Path.h"
#include <iostream>
#define DEBUG(msg) std::cout << msg << std::endl;
class Monitor {
public:
~Monitor(){}
void onItemAdded(const Poco::DirectoryWatcher::DirectoryEvent& ev);
void onItemRemoved(const Poco::DirectoryWatcher::DirectoryEvent& ev);
void onItemModified(const Poco::DirectoryWatcher::DirectoryEvent& ev);
void onItemMovedFrom(const Poco::DirectoryWatcher::DirectoryEvent& ev);
void onItemMovedTo(const Poco::DirectoryWatcher::DirectoryEvent& ev);
};
void Monitor::onItemAdded(const Poco::DirectoryWatcher::DirectoryEvent& ev)
{
DEBUG("Added: " << ev.item.path())
}
void Monitor::onItemRemoved(const Poco::DirectoryWatcher::DirectoryEvent& ev)
{
DEBUG("Removed: " << ev.item.path())
}
void Monitor::onItemModified(const Poco::DirectoryWatcher::DirectoryEvent& ev)
{
DEBUG("Modified: " << ev.item.path())
}
void Monitor::onItemMovedFrom(const Poco::DirectoryWatcher::DirectoryEvent& ev)
{
DEBUG("MovedFrom: " << ev.item.path())
}
void Monitor::onItemMovedTo(const Poco::DirectoryWatcher::DirectoryEvent& ev)
{
DEBUG("MovedTo: " << ev.item.path())
}
Poco::Path path()
{
Poco::Path p(Poco::Path::current());
p.pushDirectory(".");
return p;
}
int main(int argc, char *argv[])
{
try{
Poco::Path p(path());
p.setFileName("test.txt");
Poco::FileOutputStream fos(p.toString());
fos << "Hello, world!";
fos.close();
Poco::DirectoryWatcher dw(path().toString(), Poco::DirectoryWatcher::DW_FILTER_ENABLE_ALL, 2);
Monitor monitor;
dw.itemAdded += Poco::delegate(&monitor, &Monitor::onItemAdded);
dw.itemRemoved += Poco::delegate(&monitor, &Monitor::onItemRemoved);
dw.itemModified += Poco::delegate(&monitor, &Monitor::onItemModified);
dw.itemMovedFrom += Poco::delegate(&monitor, &Monitor::onItemMovedFrom);
dw.itemMovedTo += Poco::delegate(&monitor, &Monitor::onItemMovedTo);
Poco::Thread::sleep(1000);
Poco::FileOutputStream fos2(p.toString(), std::ios::app);
fos2 << "Again!";
fos2.close();
// loop
while(1)
Poco::Thread::sleep(2000 * dw.scanInterval());
}catch (const Poco::Exception &ex){
DEBUG(ex.what())
}
}
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
15 | C++를 위한 Lottie 라이브러리 with SDL2 | makersweb | 2021.08.15 | 979 |
14 | NAppGUI, C언어용 크로스 플랫폼 GUI 라이브러리 | makersweb | 2022.10.10 | 900 |
13 | Protocol Buffers 를 이용한 직렬화 with Conan Package Manager | makersweb | 2021.02.24 | 880 |
12 | ZeroMQ 를 이용한 Qt 응용프로그램 간 통신 | makersweb | 2021.08.28 | 874 |
11 | VSCode 와 Qbs 플러그인으로 C/C++ 개발환경 구성 | makersweb | 2021.09.12 | 874 |
10 | 윈도우에서 안드로이드 flutter 프로그래밍 개발환경 구축(with Visual Studio Code) | makersweb | 2020.09.16 | 808 |
9 | Chromium과 Ozone 층 | makersweb | 2022.03.03 | 754 |
» | Windows에서 Qt Creator + CMake + vcpkg 로 C++ 개발환경 구성 (POCO 라이브러리 DirectoryWatcher 예제) | makersweb | 2023.01.14 | 724 |
7 | 라즈베리파이에서 Redis의 Pub/Sub 패턴을 사용하는 Electron 응용프로그램 | makersweb | 2021.01.31 | 691 |
6 | 라즈베리파이4에서 openFrameworks 예제 실행 | makersweb | 2020.12.13 | 564 |
5 | CopperSpice 에 대해서 (C++ Gui 라이브러리) | makersweb | 2022.01.02 | 552 |
4 | OTA 오픈소스 프로젝트 | makersweb | 2022.08.03 | 501 |
3 | 도커(docker)설치 및 기본 명령어 | makersweb | 2019.12.02 | 487 |
2 | Flutter 위젯의 상태관리에 대해서 | makersweb | 2023.04.06 | 468 |
1 | openFrameworks 한글 폰트 설정 및 출력하기 | makersweb | 2023.02.19 | 226 |