Please see comments below:
Hi,Unfortunately, due to the provenance of 26compat and legacy drivers as
someone can help me with this issue?
i have this sample code:
using namespace std;
cout << mongo::curTimeMillis64() << endl;
originally part of the server code, you cannot include its headers
individually like this.
The only headers you may directly include are mongo/bson/bson.h and
mongo/dbclient.h. These facade headers define macros that are needed to
make the other headers actually work.
If you really just need the time_support.h header, you can pick that up
via bson.h. But, presumably you want to do more than just use BSON, so you
should include the dbclient.h header.
and compile with:This looks fine.
g++ -I/tmp/include prova.cpp -o prova -L/tmp/lib -lmongoclient
the result is:I use the 26compat of mongo cxx driver and i have also check with nm the
/tmp/ccH0vDvx.o: In function `main':
prova.cpp:(.text+0x5): undefined reference to `mongo::curTimeMillis64()'
collect2: error: ld returned 1 exit status
symbols within the library:
First, is there a particular reason you are using the 26compat driver? The
newer legacy-1.1.x releases have a huge number of improvements and bug
fixes over the older 26compat driver. If at all possible, I recommend
upgrading to at least that. Even better however would be to switch to using
the new 3.0.1 C++11 driver from the master branch. If C++11 is not an
option, I'd recommend using the plain MongoDB C driver. The 26compat and
legacy drivers are headed for end-of-life in the not too distant future.
The fact that the 't' next to the curTimeMillis64 is lowercase indicates
nm /tmp/lib/libmongoclient.so | grep curTime
00000000000ea510 t _ZN5mongo13curTimeMicrosEv
00000000000ea4f0 t _ZN5mongo15curTimeMicros64Ev
00000000000ea440 t _ZN5mongo15curTimeMillis64Ev
that the symbol has local visibility - it isn't actually exported from
libmongoclient.so, so you can't call it.
Unlike some of the other functions in time_support.h, curTimeMillis64
isn't tagged with MONGO_CLIENT_API, so it isn't part of the public
interface to the driver.
everything seems to be ok but the compile fails. Any suggestions?
I checked and curTimeMillis64 isn't exported on the legacy branch either.
So, this is arguably a bug, and if you really need to call curTimeMillsi64,
please feel free to file a bug here: https://jira.mongodb.org/browse/CXX.
Note that any fix will likely only be made to the legacy branch, not the
Your other option is to link to the static version of libmongoclient from
either branch, which does not enforce symbol visibility. If you do that,
you must add STATIC_LIBMONGOCLIENT to the compile definitions when
including the mongo driver headers.
Finally, your other option is to upgrade to one of the other, newer
drivers. If you can use C++11, I strongly recommend using the new C++11
driver on the master branch. If not, consider using the C driver.
Please let me know if there is anything else I can do to help.