1. 編譯環境
windows 10 x64, vs2017
2. 下載依賴apr, apr-iconv. apr-util
建立目錄如下:
C:/work
|_ apr
|_ apr-iconv
|_ apr-util
|_ log4cxx(名稱任意)
可以直接下載安裝包,也可以使用svn檢出項目,SVN檢出地址http://apr.apache.org/anonsvn.html
注意:檔案夾名稱必須叫:apr,apr-iconv,apr-util
注意:apr和apr-util檢出為1.5.x版本,1.6.x 缺少檔案
+ SVN檢出地址:
- apr: http://svn.apache.org/repos/asf/apr/apr/branches/1.5.x/
- apr-iconv: http://svn.apache.org/repos/asf/apr/apr-iconv/trunk/
- apr-util: http://svn.apache.org/repos/asf/apr/apr-util/branches/1.5.x/
- log4cxx 下載地址:https://mirrors.tuna.tsinghua.edu.cn/apache/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.zip 3. 下載Sed
下載目錄:http://gnuwin32.sourceforge.net/packages/sed.htm下載sed的windows版本(二進位程式,以及啟動並執行依賴dll) 並將 sed添加到系統內容變數
sed-4.2.1-bin.zip
sed-4.2.1-dep.zip 4. 在log4cxx目錄下執行 configure.bat, configure-aprutil.bat 5. 使用vs開啟 log4cxx\projects\log4cxx.dsw 6. 菜單“產生”-> “組態管理員” 將debug和release都調整為64位 7. 菜單“項目” -> “重定解決方案目標” ,4個項目依次執行,並將log4cxx設為啟動項目 8. 編譯
剛開始編譯會出現類似於以下的錯誤:
src\main\include\log4cxx\spi\loggingevent.h(155): error C2252:只能在命名空間範圍內顯式執行個體化模板’ 錯誤.
解決方案: a) 雙擊 “輸出” 視窗中的錯誤行, 此時會在 “代碼視窗” 中出現錯誤的位置. b) 選擇 LOG4CXX_LIST_DEF, 按鍵盤 F12, 此時會跳轉到該宏的定義 c) 將
#define LOG4CXX_LIST_DEF(N, T) \ template class LOG4CXX_EXPORT std::allocator<T>; \ template class LOG4CXX_EXPORT std::vector<T>; \ typedef std::vector<T> N
替換為:
#define LOG4CXX_LIST_DEF(N, T) \ typedef std::vector<T> N
如果報如下錯誤:
C2039 “insert_iterator”: 不是“std”的成員
解決辦法:
在源檔案頭部添加:#include
備忘:不建議使用log4cxx(編譯太麻煩),建議使用spdlog