$ g++ tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_system -lboost_regex -o tutorialIn file included from mongoTest.cpp:4:0:
mongo-client-install/include/m ongo/bson/bson.h:66:26: fatal error:mongo/config.h: No such file or directory
#include "mongo/config.h"
^
compilation terminated.
the file is:
#include <cstdlib>
#include <iostream>
#include "mongo-client-install/include/ mongo/bson/bson.h"
#include "mongo-client-install/include/ mongo/client/dbclient.h"
void run() {
mongo::DBClientConnection c;
c.connect("localhost");
}
int main() {
mongo::client::initialize();
try {
run();
cout << "Connect ok." << endl;
} catch (const mongo::DBException &e) {
cout << "Caught " << e.what() << endl;
}
return EXIT_SUCCESS;
}
the code to build driver:
the git clone repo is in the data partion in my HDD and i use legacy version.scons --prefix=$HOME/mongo-client-in
stall --sharedclient install
You should include the bson.h and dbclient.h files as:#include "mongo/bson/bson.h"and#include "mongo/client/dbclient.h"You need to do this because those headers contain additional #include statements that expect that files like config.h can be found when prefixed with the exact string 'mongo/client' or 'mongo/bson'. You should edit your #include lines in the example above to remove 'mongo-client-install/include', and update your compiler invocation so that the header search path is $HOME/mongo-client-install/ include. Same error.i do not understand because of this error, compilation is on the path /home/user/mongo-client-instal$ g++ mongTest.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_system -lboost_regex -o mongTestIn file included from mongTest.cpp:4:0: include/mongo/bson/bson.h:66:2
6: fatal error: mongo/config.h: No such file or directory #include "mongo/config.h" ^ compilation terminated. l. Might you tell me another way to install the legacy version please'd like to try another way. I don't see that you are specifying an include search path to g++. If you build the driver with --prefix=/path/to/install, you will end up with installed headers like /path/to/install/include/mongo/config.h. Your application should include files like #include "mongo/bson/bson.h" (e.g. no part of the prefix is present), and the g++ line to compile your application should have -I/path/to/install/include among the compile flags, and -L/path/to/install/lib -lmongoclient on the link line. To help diagnose further, could you please reiterate:- The exact SCons invocation used to build the driver- The complete source file you are trying to compile against the driver- The complete compiler invocation you are using to build your source filehey andrew, I have another error with the library boost_thread-mt, this is the error: first.and i remove -mt:$ g++ mongoTest.cpp -pthread -Imongo-client/include -Lmongo-client/lib -lboost_thread-mt -lboost_system -lboost_regex -o mongoTest/usr/bin/ld: cannot find -lboost_thread-mt collect2: error: ld returned 1 exit status
and this is boost and boost-libs informacion.$ g++ mongoTest.cpp -pthread -Imongo-client/include -Lmongo-client/lib -lboost_thread -lboost_system -lboost_regex -o mongoTest/usr/bin/ld: warning: libicuuc.so.54, needed by /usr/lib/gcc/i686-pc-linux-gnu
/4.9.1/../../../libboost_regex .so, not found (try using -rpathor -rpath-link) /usr/bin/ld: warning: libicui18n.so.54, needed by /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so, not found (try using -rpathor -rpath-link) /usr/bin/ld: warning: libicudata.so.54, needed by /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so, not found (try using -rpathor -rpath-link) /tmp/ccdfhfRA.o: In function `main': mongoTest.cpp:(.text+0xf8): undefined reference to `mongo::client::Options::Optio ns()' mongoTest.cpp:(.text+0x10b): undefined reference to `mongo::client::initialize( mongo::client::Options const&)' /tmp/ccdfhfRA.o: In function `mongo::DBException:: DBException(std::string const&, int)': mongoTest.cpp:(.text._ ZN5mongo11DBExceptionC2ERKSsi[ _ ZN5mongo11DBExceptionC5ERKSsi] +0x1b): undefined reference to `vtable formongo::DBException' /tmp/ccdfhfRA.o: In function `mongo::DBException::~ DBException()': mongoTest.cpp:(.text._ ZN5mongo11DBExceptionD2Ev[_ ZN5mongo11DBExceptionD5Ev]+0xa ): undefined reference to `vtable for mongo::DBException' /tmp/ccdfhfRA.o: In function `mongo::DBException::addContex t(std::stringconst&)': mongoTest.cpp:(.text._ ZN5mongo11DBException10addCont extERKSs[_ ZN5mongo11DBException10addCont extERKSs]+0x16): undefined reference to `mongo::causedBy(std::string const&)' /tmp/ccdfhfRA.o: In function `mongo::UserException:: UserException(int, std::string const&)': mongoTest.cpp:(.text._ ZN5mongo13UserExceptionC2EiRKS s[_ ZN5mongo13UserExceptionC5EiRKS s]+0x20): undefined reference to `vtablefor mongo::UserException' /tmp/ccdfhfRA.o: In function `mongo::UserException::~ UserException()': mongoTest.cpp:(.text._ ZN5mongo13UserExceptionD2Ev[_ ZN5mongo13UserExceptionD5Ev]+0 xb): undefined reference to `vtable for mongo::UserException' /tmp/ccdfhfRA.o: In function `mongo::DBClientConnection::DB ClientConnection(bool, mongo::DBClientReplicaSet*, double)': mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionC2 EbPNS_18DBClientReplicaSetEd[_ ZN5mongo18DBClientConnectionC5 EbPNS_18DBClientReplicaSetEd]+ 0x21): undefined reference to `mongo::DBClientBase:: DBClientBase()' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionC2 EbPNS_18DBClientReplicaSetEd[_ ZN5mongo18DBClientConnectionC5 EbPNS_18DBClientReplicaSetEd]+ 0x2d): undefined reference to `vtable for mongo::DBClientConnection' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionC2 EbPNS_18DBClientReplicaSetEd[_ ZN5mongo18DBClientConnectionC5 EbPNS_18DBClientReplicaSetEd]+ 0x37): undefined reference to `vtable formongo::DBClientConnection' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionC2 EbPNS_18DBClientReplicaSetEd[_ ZN5mongo18DBClientConnectionC5 EbPNS_18DBClientReplicaSetEd]+ 0xa6): undefined reference to `mongo::HostAndPort:: HostAndPort()' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionC2 EbPNS_18DBClientReplicaSetEd[_ ZN5mongo18DBClientConnectionC5 EbPNS_18DBClientReplicaSetEd]+ 0xfb): undefined reference to`mongo::DBClientConnection::_ numConnections' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionC2 EbPNS_18DBClientReplicaSetEd[_ ZN5mongo18DBClientConnectionC5 EbPNS_18DBClientReplicaSetEd]+ 0x19a): undefined reference to `mongo::DBClientBase::~DBClien tBase()' /tmp/ccdfhfRA.o: In function `mongo::DBClientConnection::~ DBClientConnection()': mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionD2 Ev[_ ZN5mongo18DBClientConnectionD5 Ev]+0xc): undefined reference to `vtable for mongo::DBClientConnection' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionD2 Ev[_ ZN5mongo18DBClientConnectionD5 Ev]+0x16): undefined reference to `vtablefor mongo::DBClientConnection' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionD2 Ev[_ ZN5mongo18DBClientConnectionD5 Ev]+0x20): undefined reference to `mongo::DBClientConnection::_ numConnections' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionD2 Ev[_ ZN5mongo18DBClientConnectionD5 Ev]+0xa8): undefined reference to`mongo::DBClientBase::~ DBClientBase()' mongoTest.cpp:(.text._ ZN5mongo18DBClientConnectionD2 Ev[_ ZN5mongo18DBClientConnectionD5 Ev]+0x165): undefined reference to `mongo::DBClientBase::~DBClien tBase()' /tmp/ccdfhfRA.o: In function `mongo::DBClientConnection:: connect(std::string const&)': mongoTest.cpp:(.text._ ZN5mongo18DBClientConnection7c onnectERKSs[_ ZN5mongo18DBClientConnection7c onnectERKSs]+0x41): undefined reference to`mongo::HostAndPort:: HostAndPort(mongo::StringData const&)' /tmp/ccdfhfRA.o:(.gcc_except_ table+0x48): undefined reference to `typeinfo for mongo::DBException' /tmp/ccdfhfRA.o:(.rodata._ ZTVN5mongo16ConnectExceptionE[ _ ZTVN5mongo16ConnectExceptionE] +0x18): undefined reference to `mongo::UserException:: appendPrefix(std::basic_ stringstream<char, std::char_traits<char>, std::allocator<char> >&) const' /tmp/ccdfhfRA.o:(.rodata._ ZTVN5mongo16ConnectExceptionE[ _ZTVN5mongo16ConnectExceptionE ]+0x20): undefined reference to`mongo::DBException::toString( ) const' /tmp/ccdfhfRA.o:(.rodata._ ZTVN5mongo18AssertionException E[_ ZTVN5mongo18AssertionException E]+0x20): undefined reference to `mongo::DBException::toString( ) const' /tmp/ccdfhfRA.o:(.rodata._ ZTIN5mongo16ConnectExceptionE[ _ ZTIN5mongo16ConnectExceptionE] +0x8): undefined reference to `typeinfo for mongo::UserException' /tmp/ccdfhfRA.o:(.rodata._ ZTIN5mongo18AssertionException E[_ ZTIN5mongo18AssertionException E]+0x8): undefined reference to `typeinfo for mongo::DBException' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_tolower_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `icu_54::Collator:: createInstance(icu_54::Locale const&, UErrorCode&)' /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so:undefined reference to `u_digit_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_isblank_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_isspace_54' /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so:undefined reference to `icu_54::Locale::Locale()' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_charType_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `icu_54::Locale::Locale(icu_ 54::Locale const&)' /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so:undefined reference to `u_charFromName_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `icu_54::Locale::~Locale()' collect2: error: ld returned 1 exit status thanks for you help and patience.$ pacman -Qi boost boost-libsName : boostVersion : 1.57.0-2 Description : Free peer-reviewed portable C++ source libraries -development headersArchitecture : i686 URL : http://www.boost.org/ Licenses : customGroups : None Provides : None Depends On : boost-libs=1.57.0 Optional Deps : python: for python bindings [installed] python2: for python2 bindings [installed] boost-build: to use boost jam for building your project. Required By : None Optional For : None Conflicts With : None Replaces : None Installed Size : 132440.00 KiB Packager : Evangelos Foutras <evangelos@foutrelis.com> Build Date : Thu 06 Nov 2014 03:55:04 AM ASTInstall Date : Tue 02 Dec 2014 05:56:20 PM ASTInstall Reason : Installed as a dependency for another package Install Script : No Validated By : Signature Name : boost-libsVersion : 1.57.0-2 Description : Free peer-reviewed portable C++ source libraries -runtime librariesArchitecture : i686 URL : http://www.boost.org/ Licenses : customGroups : None Provides : None Depends On : bzip2 zlib icuOptional Deps : openmpi: for mpi supportRequired By : blender boost clucene libetonyek librevenge mongodb openimageio openshadinglanguage source-highlightOptional For : None Conflicts With : None Replaces : None Installed Size : 10453.00 KiB Packager : Evangelos Foutras <evangelos@foutrelis.com> Build Date : Thu 06 Nov 2014 03:52:59 AM ASTInstall Date : Tue 02 Dec 2014 05:56:14 PM ASTInstall Reason : Installed as a dependency for another package Install Script : No Validated By : Signature
hey andrew, I have another error with the library boost_thread-mt, this is the error: first.$ g++ mongoTest.cpp -pthread -Imongo-client/include -Lmongo-client/lib-lboost_thread-mt -lboost_system -lboost_regex -o mongoTest/usr/bin/ld: cannot find -lboost_thread-mt collect2: error: ld returned 1 exit status
The specifics of the names of the boost libraries depend on how boost was configured, built, and installed. You should look at the files declared to be installed by your package manager for boost to determine what names are available. In general though, you would not want to mix the -mt and non--mt versions of these libraries.In this case it looks like you should consistently use the names that are not adorned with -mt.and i remove -mt:Many of the undefined symbols below are because you have not included -lmongoclient on your link line. Add -lmongoclient and many of the errors will be fixed.$ g++ mongoTest.cpp -pthread -Imongo-client/include -Lmongo-client/lib-lboost_thread -lboost_system -lboost_regex -o mongoTest/usr/bin/ld: warning: libicuuc.so.54, needed by /usr/lib/gcc/i686-pc-linux-gnu
/4.9.1/../../../libboost_regex .so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libicui18n.so.54, needed by /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so, not found (try using -rpath or -rpath-link) /usr/bin/ld: warning: libicudata.so.54, needed by /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so, not found (try using -rpath or -rpath-link) Note the above warnings: it is telling you at link time that dependencies of the libraries you are creating references to (in this case boost_regex) cannot satisfy their own dependencies. In this case it looks like ICU library is not located. You should check the validity/completeness of your boost installation.The errors up to here should be resolved by adding -lmongoclient/usr/lib/gcc/i686-pc-linux-
gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_tolower_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `icu_54::Collator:: createInstance(icu_54::Locale const&, UErrorCode&)' /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so:undefined reference to `u_digit_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_isblank_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_isspace_54' /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so:undefined reference to `icu_54::Locale::Locale()' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `u_charType_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `icu_54::Locale::Locale(icu_ 54::Locale const&)' /usr/lib/gcc/i686-pc-linux-gnu /4.9.1/../../../libboost_regex .so:undefined reference to `u_charFromName_54' /usr/lib/gcc/i686-pc-linux- gnu/4.9.1/../../../libboost_ regex.so: undefined reference to `icu_54::Locale::~Locale()' collect2: error: ld returned 1 exit status The above errors are related to the boost installation.Above it states that ICU is a dependency of boost. Is it installed?
댓글 없음:
댓글 쓰기