2

I am a green hands about mongoc. My mongo-c-driver is 1.6.3, and I want to do some operation to mongodb database, like create, update, insert and delete. But there are problems as shown below. My eclipse CDT contains the header file (path:/usr/local/include), but the IDE still cannot find them:

unresolved inclusion:<mongoc.h>

Can somebody give me some advice?

I installed the mongo-c-driver manually, without using the package manager.

enter image description here

Boiethios
  • 38,438
  • 19
  • 134
  • 183
Sucy
  • 488
  • 11
  • 19

3 Answers3

2

The command pkg-config outputs a flag to search at the path where the header is (not sure about the library name you must provide: check with your package manager):

$ pkg-config --cflags libmongoc
-I/usr/local/include/libmongoc-1.0/

If you use gcc, your compilation line must look like:

gcc `pkg-config --cflags libmongoc` file.c

If you use an IDE, find the way to provide this for the compilation. This is the best way to do it because if you update the library, or if you give the project to someone with a different emplacement of the headers, your project will keep to compile correctly.

Because you installed the library manually, you must

  • either install the libmongoc.pc file into the right place (man pkg-config for more information);
  • either put the flag manually: gcc -I/usr/local/include/libmongoc-1.0 file.c. The syntax -I/some/path given to the compiler means: search the header files in this place. Modify the project configuration in the IDE accordingly.
Boiethios
  • 38,438
  • 19
  • 134
  • 183
  • yes, you are right. I have try ways to add this header files into my IDE, but it's doesn't work. I will continue researching it. – Sucy Jun 30 '17 at 10:10
  • @Sucy Does `pkg-config --cflags libmongoc` give an output? – Boiethios Jun 30 '17 at 10:13
  • No packages "libmongoc" found – Sucy Jun 30 '17 at 10:15
  • and its says: Perhaps you should add the directory containing 'libmongoc.pc' – Sucy Jun 30 '17 at 10:17
  • Maybe you explicitly installed the version 1. Try with `libmongoc-1.0` instead. – Boiethios Jun 30 '17 at 10:18
  • How did you installed this package? What is the line you typed with the package manager? – Boiethios Jun 30 '17 at 10:21
  • I download mongo-c-driver 1.6.3.tar, then unpack it, ./configure, make,make install. every step according to http://mongoc.org/libmongoc/current/installing.html. – Sucy Jun 30 '17 at 10:25
  • Why did you not install mongoc with yum? `yum install mongo-c-driver` – Boiethios Jun 30 '17 at 10:26
  • This is the company's network problems, our company don't allow using internet. sorry for that. I disturb you much time. – Sucy Jun 30 '17 at 10:28
  • yeah, I should use yum, I want to know use yum or unpack there is something different? And some people may use download. – Sucy Jun 30 '17 at 10:31
  • Manually install something is not a good idea. You have issues (like with `pkg-manager` for example). – Boiethios Jun 30 '17 at 10:32
1

The include file is in "/usr/local/include/libmongoc-1.0/" but you've told Eclipse to look in "/usr/local/include/", so naturally it won't find it.

You can either add "/usr/local/include/libmongoc-1.0/" as an include path or change what you include to <libmongoc-1.0/mongoc.h>. The former is probably the more sensible option as it'll be easier to change the include path in the future than all the places where you do the include.

Chris Turner
  • 8,082
  • 1
  • 14
  • 18
0

Thanks goodness! I have solved it. No matter where you configure the mongo-c-driver, like /usr, /usr/local, or /usr/local/xxx(any name), you can find that the mongoc.h and others header files are all under libmongoc-1.0 folder, you should copy all the header file(xxxx.h)out of the libmongoc-1.0 folder and under include folder and that is will be ok. Good luck to everyone who encounter the same problem with me.

Sucy
  • 488
  • 11
  • 19