使用CMake可以很方便的实现跨平台编译。如果要Link一个第三方库,需要针对平台进行设置。这里分享下如何创建一个简单的CMake工程实现Windows, Linux和macOS上的自动编译。
SDK下载
- Dynamsoft Barcode Reader 5.2 for Windows
- Dynamsoft Barcode Reader 5.2 for Linux
- Dynamsoft Barcode Reader 5.2 for macOS
CMake下载安装
Windows
Linux
sudo apt-get install cmake
macOS
brew install cmake
注意不要在brew前面加sudo。最新的brew不再支持,用了会发生错误:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
工程结构
project
|-- platforms
|-- win
|-- DBRx86.lib
|-- DynamsoftBarcodeReaderx86.dll
|-- linux
|-- libDynamsoftBarcodeReader.so
|-- macos
|-- libDynamsoftBarcodeReader.dylib
|-- include
|