一、核心說明
如需使用 Windows 靜態(tài)庫編譯 TUTK SDK 示例項(xiàng)目,需修改兩個(gè)關(guān)鍵文件:
- 項(xiàng)目對應(yīng)的
CMakeLists.txt(添加靜態(tài)庫編譯宏定義); - 編譯腳本
build.bat(指定靜態(tài)庫目錄)。
二、修改 CMakeLists.txt
需分別修改
Sample_AVAPIs 和 Sample_IOTCAPIs 項(xiàng)目的 CMake 配置文件,核心修改:添加 -DIOTC_STATIC_LIB 宏定義。2.1 Sample_AVAPIs 項(xiàng)目 CMakeLists.txt
完整修改后代碼(關(guān)鍵修改已標(biāo)注):
project(AVAPIs_Sample)
cmake_minimum_required(VERSION 2.8)
# 關(guān)鍵修改:添加靜態(tài)庫編譯宏定義
add_definitions( -DIOTC_STATIC_LIB )
#set(ROOT_DIR "${CMAKE_SOURCE_DIR}/../../../")
include_directories(${ROOT_DIR}/Include)
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/extension)
find_library(AVAPIs_sT AVAPIs_sT HINTS ${LIB_DIR})
find_library(IOTCAPIs_sT IOTCAPIs_sT HINTS ${LIB_DIR})
find_library(json-c json-c HINTS ${LIB_DIR})
find_library(libcurl libcurl HINTS ${LIB_DIR})
find_library(libcrypto libcrypto HINTS ${LIB_DIR})
find_library(zlibstatic zlibstatic HINTS ${LIB_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}")
add_executable(AVAPIs_Client AVAPIs_Client.c extension/demoOption/demoOption.c)
target_link_libraries(AVAPIs_Client AVAPIs_sT IOTCAPIs_sT json-c libcurl libcrypto libssl Crypt32 legacy_stdio_definitions Ws2_32 winmm wldap32)
2.2 Sample_IOTCAPIs 項(xiàng)目 CMakeLists.txt
完整修改后代碼(關(guān)鍵修改已標(biāo)注):
project(IOTCAPIs_Sample)
cmake_minimum_required(VERSION 2.8)
# 關(guān)鍵修改:添加靜態(tài)庫編譯宏定義
add_definitions( -DIOTC_STATIC_LIB )
#set(ROOT_DIR "${CMAKE_SOURCE_DIR}/../../../")
include_directories(${ROOT_DIR}/Include)
include_directories(${CMAKE_SOURCE_DIR})
find_library(IOTCAPIs_sT IOTCAPIs_sT HINTS ${LIB_DIR})
find_library(json-c json-c HINTS ${LIB_DIR})
find_library(libcurl libcurl HINTS ${LIB_DIR})
find_library(libcrypto libcrypto HINTS ${LIB_DIR})
find_library(zlibstatic zlibstatic HINTS ${LIB_DIR})
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}")
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}")
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}")
add_executable(IOTCAPIs_Device IOTCAPIs_Device.c)
target_link_libraries(IOTCAPIs_Device IOTCAPIs_sT json-c libcurl libcrypto libssl Crypt32 legacy_stdio_definitions Ws2_32 winmm wldap32)
add_executable(IOTCAPIs_Client IOTCAPIs_Client.c)
target_link_libraries(IOTCAPIs_Client IOTCAPIs_sT json-c libcurl libcrypto libssl Crypt32 legacy_stdio_definitions Ws2_32 winmm wldap32)
三、修改 build.bat 編譯腳本
核心修改:將動(dòng)態(tài)庫目錄改為靜態(tài)庫目錄
Release_Static。3.1 關(guān)鍵修改點(diǎn)
原配置(動(dòng)態(tài)庫):
set LibDir=%RootDir%\Lib\Windows\x64\Release\新配置(靜態(tài)庫):set LibDir=%RootDir%\Lib\Windows\x64\Release_Static\
3.2 完整 build.bat 腳本
@echo off
set CurDir=%cd%\
set RootDir=%CurDir%\..\..\..\
# 關(guān)鍵修改:指定靜態(tài)庫目錄
set LibDir=%RootDir%\Lib\Windows\x64\Release_Static\
set BuildDir=%CurDir%\build\
set OutputDir=%CurDir%\output\
rd /s /q %OutputDir%
mkdir %BuildDir%
cd %BuildDir%
xcopy %LibDir%\*.lib %BuildDir% /E /Y
cmake -DROOT_DIR=%RootDir% -DOUTPUT_DIR=%OutputDir% -DLIB_DIR=%LibDir% -DCMAKE_GENERATOR_PLATFORM=x64 .. || exit /b 101
cmake --build . --config Release || exit /b 102
cd ..
# 如果后續(xù)需要用 VS 開發(fā)項(xiàng)目,需注釋掉下面這行
#rd /s /q %BuildDir%
