0

After installing and adding in eclipse linker mongocxx bsoncxx libs, try compile code

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
    mongocxx::instance inst{};
    mongocxx::client conn{mongocxx::uri{}};

    bsoncxx::builder::stream::document document{};

    auto collection = conn["testdb"]["testcollection"];
    document << "hello" << "world";

    collection.insert_one(document.view());
    auto cursor = collection.find({});

    for (auto&& doc : cursor) {
        std::cout << bsoncxx::to_json(doc) << std::endl;
    }
}

But it fails with error:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/MongoCxx.d" -MT"src/MongoCxx.o" -o "src/MongoCxx.o" "../src

/MongoCxx.cpp"
../src/MongoCxx.cpp:8:9: warning: #pragma once in main file [enabled by default]
 #pragma once
         ^
../src/MongoCxx.cpp:13:31: fatal error: mongocxx/client.hpp: No such file or directory
src/subdir.mk:18: recipe for target 'src/MongoCxx.o' failed
 #include <mongocxx/client.hpp>
                           ^

Maybe I did something wrong In official page I follow instruction how install https://github.com/mongodb/mongo-cxx-driver/wiki/Quickstart-Guide-(New-Driver)

I use eclipse and OS OpenSuse

Simson
  • 3,373
  • 2
  • 24
  • 38
YaroslvaV
  • 85
  • 11
  • The error message doesn't match the code you posted. – melpomene Jul 15 '16 at 10:51
  • I know its linker. Can't find mongocxx foler, but I add linker – YaroslvaV Jul 15 '16 at 10:53
  • Why do you think it's the linker? – melpomene Jul 15 '16 at 10:55
  • It can't find mongocxx, but in pc it installed and I can see it – YaroslvaV Jul 15 '16 at 11:06
  • 1
    it can't find the file `mongocxx/client.hpp`, did you add the path it's in to the include paths? This is a compiler error, not a linker error. – PeterT Jul 15 '16 at 11:41
  • Yes, I did. But it still error – YaroslvaV Jul 15 '16 at 11:42
  • did you add the path `mongocxx` or the path that contains `mongocxx`. I'm talking about the compiler flag [`-I`](http://www.rapidtables.com/code/linux/gcc/gcc-i.htm) – PeterT Jul 15 '16 at 12:17
  • /usr/local/lib64/include/mongocxx/v_noabi/mongocxx /usr/local/lib64/include/bsoncxx/v_noabi/bsoncxx mongocxx bsoncxx /usr/local/lib64/lib Thats I added – YaroslvaV Jul 15 '16 at 12:36
  • @YaroslvaV but shouldn't either add `/usr/local/lib64/include/mongocxx/v_noabi/mongocxx` and use `#include ` or add ``/usr/local/lib64/include/mongocxx/v_noabi` and use `#include `. Or is there another folder called `mongocxx ` inside `/usr/local/lib64/include/mongocxx/v_noabi/mongocxx`? – PeterT Jul 15 '16 at 13:32
  • @PeterT Noupe, but if I do it, I can see "mongocxx/..." , it has problem too P.S. maybe we may talk via skype (my nick baksarbed) – YaroslvaV Jul 15 '16 at 14:46
  • 1
    @YaroslvaV if you have a different problem then ask a new question – PeterT Jul 15 '16 at 15:02
  • The C++11 driver ships a pkgconfig file. If you built the driver correctly, it should be installed with the driver. So, add `$(pkg-config --cflags --libs libmongocxx)` to your compile invocation. If you installed the C++11 driver somewhere that isn't default searched by pkg-config, you may need to appropriately set `PKG_CONFIG_PATH` in the environment as well. – acm Jul 17 '16 at 02:20

0 Answers0