Mongo Tutorial Not working On Ubuntu Server 12.04 with G++ 4.8

Asked by Christopher Dawes

I'm having a problem compiling the Mongo tutorial code with my default g++ compiler version 4.8; it compiles just fine running

g++-4.6 tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial

But just running using g++ gives:

chrisd@romeo:~$ sudo apt-get install mongodb-dev libmongo-client-dev libboost-doc libboost-all-dev fop
[sudo] password for chrisd:
chrisd@romeo:~$ g++-4.6 tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial
chrisd@romeo:~$ g++ tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial
`.text._ZN5mongo12DBClientBaseD2Ev' referenced in section `.text._ZN5mongo12DBClientBaseD1Ev[_ZN5mongo12DBClientBaseD1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmongoclient.a(dbclient.o): defined in discarded section `.text._ZN5mongo12DBClientBaseD2Ev[_ZN5mongo12DBClientBaseD5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmongoclient.a(dbclient.o)
`.text._ZN5mongo18DBClientConnectionD2Ev' referenced in section `.text._ZN5mongo18DBClientConnectionD1Ev[_ZN5mongo18DBClientConnectionD1Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmongoclient.a(dbclient.o): defined in discarded section `.text._ZN5mongo18DBClientConnectionD2Ev[_ZN5mongo18DBClientConnectionD5Ev]' of /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmongoclient.a(dbclient.o)
collect2: error: ld returned 1 exit status

I'm using:
g++ (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

After installing mongo with:
sudo apt-get install mongodb-dev libmongo-client-dev libboost-doc libboost-all-dev fop

Doing a dpkg list shows:

chrisd@romeo:~$ dpkg --list | grep mongo
ii libmongo-client-dev 0.1.4-3 Development files for the alternate C driver for MongoDB
ii libmongo-client0 0.1.4-3 Alternate C driver for the MongoDB document-oriented datastore
ii mongodb-clients 1:2.0.4-1ubuntu2.1 object/document-oriented database (client apps)
ii mongodb-dev 1:2.0.4-1ubuntu2.1 object/document-oriented database (development)
ii mongodb-server 1:2.0.4-1ubuntu2.1 object/document-oriented database (server package)

The content of the tutorial file is:
chrisd@romeo:~$ cat tutorial.cpp
#include <cstdlib>
#include <iostream>
#include "mongo/client/dbclient.h"

void run() {
  mongo::DBClientConnection c;
  c.connect("localhost");
}

int main() {
  try {
    run();
    std::cout << "connected ok" << std::endl;
  } catch( const mongo::DBException &e ) {
    std::cout << "caught " << e.what() << std::endl;
  }
  return EXIT_SUCCESS;
}

Any help much appreciated. Thanks in advance

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gcc-4.8 Edit question
Assignee:
No assignee Edit question
Solved by:
Christopher Dawes
Solved:
Last query:
Last reply:
Revision history for this message
Thomas Krüger (thkrueger) said :
#1

It looks like a problem with the testbuild of the Ubuntu toolchain you installed.
You should report it a a bug. See https://wiki.ubuntu.com/ToolChain for details.

Revision history for this message
Christopher Dawes (laenchpad) said :
#2

Thanks, I'll give that a go