log4cpp工程是靜態鏈接庫,log4cppDLL是動態鏈接庫;log4cpp只有MS vc6的工程文件。但使用vs2003將dsp轉換成vcproj之後編譯的過程中會出現錯誤,
問題一:
報錯error PRJ0019: 工具從"正在執行自定義生成步驟",詳細可以查看其BuildLog.htm。
解決辦法,將轉換後的vcproj打開,需要手工修改,原來的倒數幾行的如下內容,使用了錯誤的可執行文件路徑和錯誤的雙引號,請注意,有的人說需要把NTEventLogCategories.mc這個文件刪掉,我在我的機子上驗證了下,那個文件不能刪,並且需要把下面的內容替換替換爲後面的內容:
<FileConfiguration Name="Debug|Win32">
<Tool Name="VCCustomBuildTool" CommandLine="if not exist $(OutDir) md $(OutDir)
"$(DevEnvDir)../Tools/Bin/mc.exe" -h $(OutDir) -r $(OutDir) $(ProjectDir)../$(InputName).mc
"$(DevEnvDir)../../vc7/Bin/RC.exe" -r -fo $(OutDir)/$(InputName).res $(OutDir)/$(InputName).rc
"$(DevEnvDir)../../VC7/Bin/link.exe" /MACHINE:IX86 -dll -noentry -out:$(OutDir)/NTEventLogAppender.dll $(OutDir)/$(InputName).res"
Outputs="$(OutDir)/NTEventLogAppender.dll"/>
</FileConfiguration>
<FileConfiguration Name="Release|Win32">
<Tool Name="VCCustomBuildTool" CommandLine="if not exist $(OutDir) md $(OutDir)
"$(DevEnvDir)../Tools/Bin/mc.exe" -h $(OutDir) -r $(OutDir) $(ProjectDir)../$(InputName).mc
"$(DevEnvDir)../../vc7/Bin/RC.exe" -r -fo $(OutDir)/$(InputName).res $(OutDir)/$(InputName).rc
"$(DevEnvDir)../../VC7/Bin/link.exe" /MACHINE:IX86 -dll -noentry -out:$(OutDir)/NTEventLogAppender.dll $(OutDir)/$(InputName).res"
Outputs="$(OutDir)/NTEventLogAppender.dll"/>
</FileConfiguration>
替換爲:
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCustomBuildTool"
CommandLine="if not exist "$(OutDir)" md "$(OutDir)"
"$(DevEnvDir)../../VC98/Bin/mc.exe" -h "$(OutDir)" -r "$(OutDir)" "$(ProjectDir)"../"$(InputName)".mc
"$(DevEnvDir)Bin/RC.exe" -r -fo "$(OutDir)"/"$(InputName)".res "$(OutDir)"/"$(InputName)".rc
"$(DevEnvDir)../../VC98/Bin/link.exe" /MACHINE:IX86 -dll -noentry -out:"$(OutDir)"/NTEventLogAppender.dll "$(OutDir)"/"$(InputName)".res
"
Outputs="$(OutDir)/NTEventLogAppender.dll"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCustomBuildTool"
CommandLine="if not exist "$(OutDir)" md "$(OutDir)"
"$(DevEnvDir)../../VC98/Bin/mc.exe" -h "$(OutDir)" -r "$(OutDir)" "$(ProjectDir)"../"$(InputName)".mc
"$(DevEnvDir)Bin/RC.exe" -r -fo "$(OutDir)"/"$(InputName)".res "$(OutDir)"/"$(InputName)".rc
"$(DevEnvDir)../../VC98/Bin/link.exe" /MACHINE:IX86 -dll -noentry -out:"$(OutDir)"/NTEventLogAppender.dll "$(OutDir)"/"$(InputName)".res
"
Outputs="$(OutDir)/NTEventLogAppender.dll"/>
</FileConfiguration>
問題二:
問題:log4cppDLL項目編譯時會報8個連接錯誤,提示符號std::_Tree找不到
解決方案:
將include/log4cpp/FactoryParams.hh文件中的
const_iterator find(const std::string& t) const;
修改爲
const_iterator find(const std::string& t) const { return storage_.find(t); }
後重新編譯
問題三:
問題:log4cppDLL項目編譯時會報1個連接錯誤,提示符號log4cpp::localtime找不到
解決方案:
將src/localtime.cpp文件添加到項目中重新編譯
問題四:
問題:log4cppDLL項目編譯時找不到localtime_s找不到符號
解決方案:因爲VS版本低,所以頭文件time.h裏面沒有這個函數,打開src裏面的文件Localtime.cpp,
修改爲localtime_s(t, time);爲
::tm* tmp = ::localtime(time);
memcpy(t, tmp, sizeof(::tm));
編譯則通過;
問題五:
問題:編譯testPattern工程時,提示找不到localtime符號
解決方案:log4cpp項目編譯時,把src/localtime.cpp文件添加到項目的Source Files中;
把src/localtime.hh文件添加到項目的Header Files中重新編譯;
log4cpp應用手冊
1 下載log4cpp並解壓。
2 打開/log4cpp-0.3.4b/msvc6/msvc6.dsw
編譯log4cpp工程Release版。
3 將編譯後的log4cpp.lib複製到VC的Lib目錄中。
4 將頭文件的目錄log4cpp-0.3.4b/include/log4cpp/
複製到VC的Include目錄.
(或者添加log4cpp-0.3.4b/include到VC的Include環境變量)
6 目標工程包含庫
log4cpp.lib ws2_32.lib
(要選擇庫連接方式相同的庫)