天天看點

Caffe: gflag編譯出現問題彙總

1. 使用Unicode字元集:

出現問題

E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-master\src\gflags.cc(1340): error C2664: \'BOOL PathMatchSpecW(LPCWSTR,LPCWSTR)\' : cannot convert argument 1 from \'const char *\' to \'LPCWSTR\'

E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-master\src\gflags.cc(1340): error C2664: \'BOOL PathMatchSpecW(LPCWSTR,LPCWSTR)\' : cannot convert argument 1 from \'const char *\' to \'LPCWSTR\'

          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

       Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

 E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-master\src\gflags.cc(1341): error C2664: \'BOOL PathMatchSpecW(LPCWSTR,LPCWSTR)\' : cannot convert argument 1 from \'const char *\' to \'LPCWSTR\'

E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-master\src\gflags.cc(1341): error C2664: \'BOOL PathMatchSpecW(LPCWSTR,LPCWSTR)\' : cannot convert argument 1 from \'const char *\' to \'LPCWSTR\'

2.使用多字元集:

出現問題:

 gflags.obj : error LNK2019: unresolved external symbol __imp_PathMatchSpecA referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl google::`anonymous namespace\'::CommandLineFlagParser::ProcessOptionsFromStringLocked(class

std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum google::FlagSettingMode)" (?ProcessOptionsFromStringLocked@CommandLineFlagParser@?A0x2a9c2311@google@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV45@W4FlagSettingMode@3@@Z)

E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-sol\lib\Release\gflags_static.lib : fatal error LNK1120: 1 unresolved externals

gflags.obj : error LNK2019: unresolved external symbol __imp_PathMatchSpecA referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl google::`anonymous namespace\'::CommandLineFlagParser::ProcessOptionsFromStringLocked(class

std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum google::FlagSettingMode)" (?ProcessOptionsFromStringLocked@CommandLineFlagParser@?A0x2a9c2311@google@@QEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV45@W4FlagSettingMode@3@@Z)

E:\CodeBase\ML\Caffe\ThirdPartySrc\gflags-sol\lib\Release\gflags_nothreads_static.lib : fatal error LNK1120: 1 unresolved externals

無法定位的外部函數????

3.出現此問題參考文章:Google開源指令行參數解析庫gflags

查閱資料發現是沒有連結上shlwapi.lib,而shlwapi.lib是已經被廢棄的庫;連結上shlwapi.lib庫後再次編譯連結就OK了。

考慮到shlwapi.lib和gflags庫都是靜态庫,是以可以在生成gflags庫時連結上shlwapi.lib,這樣在應用程式中就不用額外地再連結上shlwapi.lib了。

另外需要注意的是,在VS【屬性】-【調試】中設定的原始指令行參數argv[]中表示字元串内容不僅僅是設定的相應字元串,他會在字元串前加上工程路徑名,而gflags中就沒有了工程路徑名,設定的多少就是多少。

解決方法:

        在linker裡面添加 ShLwApi.Lib

然後配置:static 為靜态庫;配置 gflag為動态庫;

4. 出現

       error LNK2001: unresolved external symbol __DllMainCRTStartup@12

解決方法:

        添加:msvcrt.lib

5.關于編譯glog

      glog依然使用了gflag,也需要引用 ShLwApi.Lib 庫

Caffe: gflag編譯出現問題彙總