【问题标题】:Making a simple app that logs and reads in command line arguments with Visual Studio 2010 Express, google glog and google gflags?使用 Visual Studio 2010 Express、google glog 和 google gflags 制作一个简单的应用程序来记录和读取命令行参数?
【发布时间】:2011-03-05 03:45:09
【问题描述】:

我编写了以下简单程序:

#include "stdafx.h"
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <ostream>
int _tmain(int argc, char* argv[])
{

    google::InitGoogleLogging(argv[0]);


    LOG(INFO) << "Found";
    return 0;
}

我从这里查看了 google-glog:http://code.google.com/p/google-glog/source/checkout

我已经从这里查看了 google-gflags:http://code.google.com/p/google-gflags/

我在 Visual Studio 2010 Express 中拥有所有这三个项目,都在同一个解决方案下:

  • 解决方案
    • GoogleLibsTest
    • libgflags
    • libglog

当我编译它时,我得到以下错误:

1>------ Build started: Project: GoogleLibsTest, Configuration: Debug Win32 ------
1>GoogleLibsTest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall google::LogMessage::~LogMessage(void)" (__imp_??1LogMessage@google@@QAE@XZ) referenced in function _wmain
1>GoogleLibsTest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall google::LogMessage::stream(void)" (__imp_?stream@LogMessage@google@@QAEAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@XZ) referenced in function _wmain
1>GoogleLibsTest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall google::LogMessage::LogMessage(char const *,int)" (__imp_??0LogMessage@google@@QAE@PBDH@Z) referenced in function _wmain
1>GoogleLibsTest.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl google::InitGoogleLogging(char const *)" (__imp_?InitGoogleLogging@google@@YAXPBD@Z) referenced in function _wmain
1>C:\Users\leeand00\Desktop\glogNgflagsTest\GoogleLibsTest\Debug\GoogleLibsTest.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========

我已经做了几件事来尝试解决这个问题,包括:

  • 在解决方案属性页面中选择公共属性项目>依赖项并将 GoogleLibsTest 设置为依赖于其他两个项目。

  • 在 GoogleLibsTest 属性页面中

    • 将 libgflags-debug.lib libglog_static.lib 添加到 Configuration Properties>Linker>Input>Additional Dependencies 列表。

    • 在配置属性>VC++ 目录中,我将包含 libgflags-debug.lib 和 libglog_static.lib 的目录添加到库目录列表中。

    • 在 Configuration Properties>C/C++>General>Additional Include Directories 中添加了 \src\windows 的路径(因为这是 glog 的头文件所在的位置)

    • 在 Configuration Properties>C/C++>General>Additional Include Directories 中添加了 \src\windows 的路径(因为这是 gflags 的头文件所在的位置)

由于某种原因,它正在寻找一个 dll 文件(我不知道这是为什么)

我还有什么遗漏的吗?

【问题讨论】:

  • 我正在尝试将 glog 与 Visual Studio 2012 一起使用,并且遇到了同样的问题。我尝试使用静态库和 dll,但我真的不知道出了什么问题。你成功了吗?

标签: visual-c++ visual-studio-2010


【解决方案1】:

您似乎想静态链接到 glog,但忘记定义 "GOOGLE_GLOG_DLL_DECL=" 宏,只需查看 glog 附带的 logging_unittest_static 项目。

虽然我认为在 Windows 上使用 glog 和 gflags 时还有一些其他问题。查看this link

【讨论】:

  • 谢谢,这行得通!在 Visual Studio C/C++->预处理器中粘贴“GOOGLE_GLOG_DLL_DECL=”(注意包括等号)
【解决方案2】:

假设您的项目已经将“附加包含目录”设置为 GLOG 项目文件夹的 src/windows,然后检查以下内容:

1) 确保 GLOG 和您的应用程序都以 32 位或 64 位编译(截至目前,GLOG 似乎仅在发布模式下编译 64 位) 2) 确保 libglog.dll 在您的系统路径中 3) 确保在项目的“附加依赖项”中设置了 libglog.lib(在 Linker->Input 下) 4) 确保 libglog.lib 的路径设置在项目的“附加库目录”中(在 Linker->General 下)

【讨论】:

    猜你喜欢
    • 2014-06-28
    • 2011-03-03
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 2011-09-14
    • 2011-09-04
    • 1970-01-01
    相关资源
    最近更新 更多