Re: Get boost error when building a test application for mongoclient.lib on Windows 7 x64 with VS 2010 for MongoDB 2.2.

720 views
Skip to first unread message

Peng Liu

unread,
Dec 11, 2012, 8:31:14 PM12/11/12
to mongo...@googlegroups.com
Yes, I am sure I set the target X64. Actually I also try win32 version, I also get the same problem.

On Tuesday, December 11, 2012 1:51:38 PM UTC+8, Ryan Capote wrote:
Make sure you're targeting x64 in properties->Configuration Manager

On Sunday, December 9, 2012 6:16:47 PM UTC-8, Peng Liu wrote:
I try to write a test application to try how to use mongoclient.lib on 64bit Windows 7 SP1. I use Visual Studio 2010 Professional and Boost 1.4.2. I built the Boost library by myself with the command:
  bjam msvc stage --build-type=complete address-model=64
I built the mongodb components with the command:
  scons --64
  scons --dd --64 mongoclient.lib
  scons --dd --64 core
Then I copy the boost src files, library and mongo src files and mongoclient.lib to my specific third party source and lib directories, such as ThirdParty\boost including boost and lib subdirectory, ThirdParty\mongodb including include and lib subdirectory.

In my test application solution, I modify the project properties as follow:
1. VC Diretories->"Include Directories" and "Library Directories": add my specific third party source directory.
2. C/C++->Proprocessor Definition: add _CRT_SECURE_NO_WARNINGS
3. C/C++->Code Generation->Runtime library: MTd
4. Linker->Input: add ws2_32.lib, dbghelp.lib, mongoclient.lib and the 5 boost libraries.

The code is as follow:
#include "stdafx.h"
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
using namespace bson;

int _tmain(int argc, _TCHAR* argv[])
{
  try
  {
    cout << "connect to localhost mongodb server" << endl;
    DBClientConnection c;
    c.connect("localhost");
    string errstr = c.getLastError();
  }
  catch(DBException& e) {
    cout << "caught DBException " << e.toString() << endl;
    return 1;
  }
    return 0;
}

Then I get the building errors below.
I also try the boost prebuilt library downloaded from http://www.mongodb.org/pages/viewpageattachments.action?pageId=12157032. But fail.
I can build the example project which is in mongodb source and run dbclient without library.

Can any experts help that?

Thanks.

1>------ Build started: Project: MongoDBAccess, Configuration: Debug x64 ------
1>mongoclient.lib(log.obj) : error LNK2019: unresolved external symbol "class boost::filesystem2::file_status __cdecl boost::filesystem2::detail::status_api(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class boost::system::error_code &)" (?status_api@detail@filesystem2@boost@@YA?AVfile_status@23@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAVerror_code@system@3@@Z) referenced in function "bool __cdecl boost::filesystem2::exists<class boost::filesystem2::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem2::path_traits> >(class boost::filesystem2::basic_path<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct boost::filesystem2::path_traits> const &)" (??$exists@V?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem2@boost@@@filesystem2@boost@@@filesystem2@boost@@YA_NAEBV?$basic_path@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Upath_traits@filesystem2@boost@@@01@@Z)
1>mongoclient.lib(util.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(dbmessage.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(log.obj) : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "public: __cdecl boost::system::error_code::error_code(void)" (??0error_code@system@boost@@QEAA@XZ)
1>mongoclient.lib(syncclusterconnection.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(dbclient_rs.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(dbclientcursor.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(util.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(dbmessage.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(log.obj) : error LNK2019: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ) referenced in function "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" (??__Eposix_category@system@boost@@YAXXZ)
1>mongoclient.lib(syncclusterconnection.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(dbclient_rs.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ)
1>mongoclient.lib(dbclientcursor.obj) : error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAAEBVerror_category@12@XZ)
1>D:\Private\Test\MongoDBDemo\MongoDBAccess\x64\Debug\MongoDBAccess.exe : fatal error LNK1120: 3 unresolved externals

Eric Milkie

unread,
Dec 12, 2012, 7:23:02 AM12/12/12
to mongo...@googlegroups.com
It looks like the missing symbols are from the boost system and boost filesystem libraries.  When you say you are linking in the 5 boost libraries, which ones in particular are those?
-Eric

--
You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-dev/-/aYvV1tyDwKUJ.
To post to this group, send email to mongo...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-dev?hl=en.

Peng Liu

unread,
Dec 12, 2012, 8:34:46 PM12/12/12
to mongo...@googlegroups.com
Hi, Eric,
I also think so. But I confuse that why the boost library I built doesn't work.
In Visual studio Configuration Properties->Linker->Input->Additional Dependencies, I set as follow:
ws2_32.lib
libboost_system-vc100-mt-sgd-1_42.lib
libboost_date_time-vc100-mt-sgd-1_42.lib
libboost_filesystem-vc100-mt-sgd-1_42.lib
libboost_program_options-vc100-mt-sgd-1_42.lib
dbghelp.lib
libboost_thread-vc100-mt-sgd-1_42.lib
mongoclient.lib

Eric Milkie

unread,
Dec 12, 2012, 8:43:46 PM12/12/12
to mongo...@googlegroups.com
You can try using "dumpbin /exports" on libboost_system-vc100-mt-sgd-1_42.lib and see if one of the missing boost::system symbols is there.  If it's there, then it's a linker command line issue.  If it's not there, that means the way you built the library isn't lining up with the way the MongoDB C++ driver is being built.  The calling standards need to be the same between the different libraries -- this is specified via a compiler flag.
-Eric



To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-dev/-/TTIJPjorUrAJ.

Peng Liu

unread,
Dec 14, 2012, 4:55:23 AM12/14/12
to mongo...@googlegroups.com
I run command below to dump the symbols.
dumpbin libboost_system-vc100-mt-sgd-1_42.lib /SYMBOLS >dump.txt

And I can't find the symbol "boost::system::generic_category" but I can find "boost::system::get_generic_category" . It seems that the header and lib don't match. On stackoverflow, some threads say that "boost::system::get_generic_category" is deprecated. It might cause this problem when linking older headers against new library.

If that's true, where can I find the latest boost 1.4.2 which including "boost::system::generic_category" instead of "boost::system::get_generic_category"?

BR,
Liu Peng

Eric Milkie

unread,
Dec 14, 2012, 9:58:06 AM12/14/12
to mongo...@googlegroups.com
For boost::system::generic_category, do you mean you looked for this mangled name: ?generic_category@system@boost@@YAAEBVerror_category@12@XZ
What symbols do you see in your boost library that contain the text "generic_category"? I think that boost::system::generic_category should be in the boost system library, although the name mangling might be different. The name mangling might not match because you are using mismatched calling standards when you compile them.
-Eric

Peng Liu

unread,
Dec 16, 2012, 8:50:25 PM12/16/12
to mongo...@googlegroups.com
Hi, Eric,

Actually I can find ?get_generic_category@system@boost@@YAAEBVerror_category@12@XZ (class boost::system::error_category const & __cdecl boost::system::get_generic_category(void)) instead of ?generic_category@system@boost@@YAAEBVerror_category@12@XZ. So, I guess the boost 1.4.2 I use to build library is different from the one in mongoDB source, which is newer.

I download the boost 1.4.2 from boost website to build the static library. Maybe I need to find a new one. But, where to get it?

BR,
Liu Peng

Eric Milkie

unread,
Dec 16, 2012, 8:57:32 PM12/16/12
to mongo...@googlegroups.com
Hi Liu Peng.
I recommend Boost 1.49, which you can get from here: http://sourceforge.net/projects/boost/files/boost/1.49.0/
-Eric

--
You received this message because you are subscribed to the Google Groups "mongodb-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-dev/-/H4TYw1efmioJ.

Peng Liu

unread,
Dec 17, 2012, 4:28:55 AM12/17/12
to mongo...@googlegroups.com
Hi, Eric,

If using Boost 1.49, what should I do? Replace the source code of Boost in mongoDB thirdparty directory with 1.49 and reuild all the components? Or just rebuild the mongoclient lib? Or I don't need to rebuild it?

Sorry for the repeated messages if you receive.

Thanks,
Liu Peng

Eric Milkie

unread,
Dec 17, 2012, 10:15:47 AM12/17/12
to mongo...@googlegroups.com
Hi Liu Peng,
The MongoDB source code has Boost 1.49 imported within it, so you shouldn't need to rebuild anything for libmongoclient.a.
All that is necessary will be to link against Boost 1.49 in your application.
-Eric


To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-dev/-/29PiTaPIhT4J.

Peng Liu

unread,
Dec 19, 2012, 9:01:25 PM12/19/12
to mongo...@googlegroups.com
Hi, Eric,

I build the boost 1.49. The build command is "D:\Private\Technical\C++\boost_1_49_0>b2 --toolset=msvc-10.0 --build-type=complete address-model=64 stage".
Try the boost 1.49 lib, but I get strange LINK Error:

LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc100-mt-sgd-1_42.lib'.

I check my project configuration of Linker input, no boost library of 1.42 is specified.
The mongodb source I used to build the mongoclient.lib is mongodb 2.2.0.

Thanks
LiuPeng
Reply all
Reply to author
Forward
0 new messages