I've written the following simple program:
#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;
}
I checked out google-glog from here: http://code.google.com/p/google-glog/source/checkout
And I've checked out google-gflags from here: http://code.google.com/p/google-gflags/
I have all three of these projects in Visual Studio 2010 Express, all under the same solution:
- Solution
- GoogleLibsTest
- libgflags
- libglog
When I compile it, I get the following error:
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 ==========
I've done several things to try and fix this including:
In the Solution Property page Selecting Common Properties Project>Dependencies and setting the GoogleLibsTest to depend on the other two projects.
In the GoogleLibsTest Property page
Adding libgflags-debug.lib libglog_static.lib to the Configuration Properties>Linker>Input>Additional Dependencies list.
In Configuration Properties>VC++ Directories I added the directory containing libgflags-debug.lib and libglog_static.lib to the list of library directories.
In Configuration Properties>C/C++>General>Additional Include Directories added the paths to the <glog-base-dir>\src\windows (since this is where the header files are for glog)
In Configuration Properties>C/C++>General>Additional Include Directories added the paths to the <gflags-base-dir>\src\windows (since this is where the header files are for g开发者_高级运维flags)
For some reason it is looking for a dll file (I don't know why that is)
Is there anything else I'm missing?
It seems that you want to static link to glog, but forget to define "GOOGLE_GLOG_DLL_DECL=" macro, just check out logging_unittest_static project shipped with glog.
Though I think there're some other problems when using glog with gflags on Windows. Check out this link
Assuming that your project already has the "Additional Include Directories" set to src/windows of the GLOG project folder, then check the following:
1) Make sure that both GLOG and your app is compiled in either 32 or 64 bit (as of this date GLOG only seems to compile 64 bit in release mode) 2) Make sure that libglog.dll is in your system path 3) Make sure that libglog.lib is set in your project's "Additional Dependencies" (under Linker->Input) 4) Make sure that the path to libglog.lib is set in your project's "Additional Library Directories" (under Linker->General)
精彩评论