Connecting Mongodb to C++ API #include problems - c++

I got the mongoshell and Json file all set up. I need help connecting Mongodb to C++
I typed this in the command prompt but it gave a a syntax error. (my file name is ConnectorMain.cpp)
-I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain.cpp -o ConnectorMain
This person had the same problem: Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory
The reason that there you need to type this in the cmd pmt is because it will allow you to access the weird #inclue files like: #include "mongo/client/dbclient.h"
I've visited http://api.mongodb.org/cplusplus/current/files.html
and this is the dbclient.h file
#pragma once
#ifdef MONGO_EXPOSE_MACROS
#error dbclient.h is for C++ driver consumer use only
#endif
#define LIBMONGOCLIENT_CONSUMER
#include "mongo/client/redef_macros.h"
#include "mongo/pch.h"
#include "mongo/client/connpool.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/client/dbclientinterface.h"
#include "mongo/client/gridfs.h"
#include "mongo/client/init.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/client/syncclusterconnection.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/client/undef_macros.h"
and it is crazy cause of all the headers so I am trying to figure out how to hook this all up and as the forum says it has to do with setting up a -I or -L because it relates to this forum http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/#installing-the-driver-library-and-headers but that is in Linux.
Please help if you know how to do this. p.s. do I need to download boost and perl or something I saw that on another post. Anyways all the help is appreciated!

Related

How to declare the Paho MQTT C++ in another c++ file?

Below is my project structure,
root#user-VirtualBox:/home/user/octane_etk_sample-6.0.0.240# ls
bin include paho.mqtt.c speedway_embedded_example.cpp
cap lib paho.mqtt.cpp VERSION
cap_description.in Makefile SCMREV
I have the paho.mqtt.cpp package inside the project directory i.e.,octane_etk_sample-6.0.0.240 and I have installed all the steps which is mentioned in https://github.com/eclipse/paho.mqtt.cpp.
Now, I have included the MQTTAsync header file in speedway_embedded_example.cpp as like below,
#include <iostream>
#include <string>
#include <algorithm>
#include <signal.h>
#include <stdio.h>
#include <cstdlib>
#include "ltkcpp.h"
#include "impinj_ltkcpp.h"
#include "time.h"
#include "/home/user/octane_etk_sample-6.0.0.240/paho.mqtt.c/src/MQTTAsync.h"
After including the header file, I am trying to establish the MQTT client connection inside the public class,
void
CMyApplication::printOneTagReportData (
CTagReportData * pTagReportData)
{
string address = "tcp://mqtt1.mindlogic.com:1883";
cout << "OK\n" << address;
mqtt::async_client cli(address, "", 120, "data-persist");
}
When I try to make a speedway_embedded_example file, I am getting below error,
root#user-VirtualBox:/home/mindlogic/octane_etk_sample-6.0.0.240# make
mkdir -p ./bin
g++ \
-m32 -Wno-write-strings \
-Iinclude \
speedway_embedded_example.cpp \
-Llib -lltkcpp_x86 -lltkcppimpinj_x86 -lxml2_x86 \
-L/usr/bin -ldl -lssl -lcrypto \
-o bin/speedwayr_x86
speedway_embedded_example.cpp: In member function ‘void CMyApplication::printOneTagReportData(LLRP::CTagReportData*)’:
speedway_embedded_example.cpp:1650:4: error: ‘mqtt’ has not been declared
mqtt::async_client cli(address, "", 120, "data-persist");
Will anyone help me out to establish a client connection in the above scenario?
You're including the C library, which doesn't have namespaces.
You (likely) want the C++ library.
https://github.com/eclipse/paho.mqtt.cpp
Or better yet, since you included the embedded tag, you may want to use
https://github.com/eclipse/paho.mqtt.embedded-c
which has embedded code for both C and C++. You should use the example code provided by the library you're using.

Qt5 & OpenGL: stdlib.h: No such file or directory

I started studying how to integrate GLFW, GLAD and OpenGL in my Qt5 project. I am getting this stdlib.hno such file or directory error.
The example I am trying to run is from official OpenGL documentation.
This document describes very well the procedure for running the project and from here all the other sessions.
My stdlib.h is present on /usr/include/stdlib.h as it is possible to see from this print screen:
In addition to that I have this strange error where the compiler expects curly brackets but could not figure out the reason of this error:
A more detailed description of the error is here:
I have been researching a lot this error, I looked here, and here and even I used this source but could not figure out what the problem is and how to link the library, which is already in the shown path.
The snipped of code is:
helloOpenGL.pro
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
LIBS += -L "/usr/lib" \
-lX11 -lpthread -lXrandr -lXi -ldl -lGL
INCLUDEPATH += "/usr/include"
LIBS += -L "/usr/include/GLFW" \
-lglfw3
and the main includes I have on the main.cpp are the following:
#include <../glad/glad.h>
#include <../GLFW/glfw3.h>
#include <iostream>
#include <stdlib.h>
Thanks for shedding light on this issue.
Try changing
#include <../glad/glad.h>
#include <../GLFW/glfw3.h>
#include <iostream>
#include <stdlib.h>
to
#include <cstdlib>
#include <iostream>
#include "../glad/glad.h"
#include "../GLFW/glfw3.h"
and see if that changes the error. Changing to cstdlib over stdlib.h is because stdlib.h is a C header not a C++ header, and cstdlib does some namespace stuff and a few slight modifications to make it a bit more C++ish as described here. As for changing <> to "" with the glad and GLFW headers, that just changes where the preprocessor searches for the headers which might be related to your error too.
As for the issue, headers and their order in C++ are important. I have a gut feeling that the ordering here is causing some issue. Please change it around and if it is not fixed, hopefully it reveals a little bit more about the issue.

Compiler unable to link/find GLFW [duplicate]

This question already has answers here:
How do I link GLFW
(3 answers)
Closed 4 years ago.
I am trying to run a modified program that can be found at cpp-pointcloud.cpp. I am having difficulties getting it to build.
As it is now my file structure is:
-pointcloud.cpp
-librealsense/
-examples
-example.hpp
And I am building it with the command:
g++ -std=c++11 pointcloud.cpp -lrealsense -lopencv_core -lopencv_imgproc -lopencv_highgui -o ir
The imports of the pointcloud.cpp file are as follows:
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.
#include <librealsense/rs.hpp>
#include <librealsense2/rs.hpp>
#include "librealsense/examples/example.hpp"
#include <chrono>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
And they are:
#pragma once
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
In the example.hpp file.
My issue is that it cannot seem to find the glfw files. I get a bunch of errors like:
pointcloud.cpp:(.text+0xdf5): undefined reference to `glPopMatrix'
Which is bizarre to me as I'm confident that i've installed the GLFW3 package. And I believed that includes that use the angle brackets search for installed packages on your operating system.
I've ran this command successfully:
sudo apt-get install libglfw3 libglfw3-dev
I tried adding
#include <GLFW/glfw3.h>
to the pointcloud.cpp file but it actually gave me more errors!
I miss be misunderstanding something conceptually here, so if any of you could point me in the right direction that would be great thanks.
You have to link GLFW with pkg-config cf How do I link GLFW
$ gcc `pkg-config --cflags glfw3` -o foo foo.c `pkg-config --static --libs glfw3`
you can locate the libraries using locate or whereis ( update database before with sudo updatedb , https://unix.stackexchange.com/questions/194088/how-to-check-if-a-shared-library-is-installed ) or find ( /www.lifewire.com/uses-of-linux-command-find-2201100 ) i.e.
sudo updatedb ( may take some time ... )
locate libglfw
or
sudo find /usr/lib -name '*libglfw*'
possibly also check all dependencies required for libglfw using ldd

Compile error : fatal error: 'boost/numeric/ublas/matrix.hpp' file not found

These are the header files and libraries
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <numeric>
#include <strings.h>
#include <assert.h>
#include <dirent.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include "mail.h"
I am trying to compile this c++ file I got using
g++ -O3 -DNDEBUG -o evaluate_object evaluate_object.cpp
The compile output
evaluate_object.cpp:13:10: fatal error: 'boost/numeric/ublas/matrix.hpp' file
not found
#include <boost/numeric/ublas/matrix.hpp>
^
1 error generated.
Ps: I run on macos sierra 10.12
I have tried install boost by these ways:
sudo port install boost
brew install boost
sudo port install boost +universal
But I still got the same problem.
I would be happy to get out of this noob zone.
I am a macos newbie too.
It seems that your "boost" includes directory is not present within environment defined include directories. You might want to specify one by passing "-I" argument to g++ command, i.e.
g++ -O3 -DNDEBUG -I/usr/local/Cellar/blahblah -o evaluate_object evaluate_object.cpp
Also your code is incomplete and perhaps if you actually call some of the boost functions you might need to add some objects for linking and then you will face "undefined reference to" error. To overcome such you need to specify "-L" flag for your g++ command.

g++ "does not name a type" error

I'm working on a little project for my structures class and have run into an issue even the TA couldn't figure out. It was suggested that I post about it on here and I might get some help. So here it goes:
Overview:
I'm using g++ to compile a project containing a number of header (.h) files along with their corresponding implementation (.cpp) files. The project involves 3 separate structures and running a timing comparison between them. The structures being implemented and compared are a binary min heap, a leftist heap, and a skew heap. The min heap implementation is complete and is compiling just fine. However now that I'm moving onto the other structures I'm running into what I assume (I know) is a compiler error.
The Issue
I'm fleshing out the stub files for the leftist heap and have hit a brick wall as far as the compiler is concerned. In particular I'm getting an error that reads:
leftHeap.cpp:15:1: error: ‘LeftistHeap’ does not name a type
The Code
Here's a look at relevant code:
leftHeap.h
#ifdef LEFTHEAP_H
#define LEFTHEAP_H
class LeftistHeap{
public:
int *root;
LeftistHeap();
~LeftistHeap();
};
#endif
leftHeap.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include "leftHeap.h"
using namespace std;
//Constuctor
LeftistHeap::LeftistHeap(){
root = NULL;
}
The only other place that leftHeap.h is included is in the main.cpp
main.cpp
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include <math.h>
#include "minHeap.h"
#include "leftHeap.h"
#include "skewHeap.h"
using namespace std;
int main(){
...
here's the makefile I'm using:
makefile
all: lab10
lab10: comparison.o minHeap.o leftHeap.o skewHeap.o
g++ comparison.o minHeap.o leftHeap.o skewHeap.o -o lab10
comparison.o: comparison.cpp
g++ -c comparison.cpp
minHeap.o: minHeap.h minHeap.cpp
g++ -c minHeap.h minHeap.cpp
leftHeap.o: leftHeap.h leftHeap.cpp
g++ -c leftHeap.h leftHeap.cpp
skewHeap.o: skewHeap.h skewHeap.cpp
g++ -c skewHeap.h skewHeap.cpp
clean:
rm lab10 *.o
and just to be extra thorough I've also tried a more minimalist makefile
makefile (2)
test:
g++ minHeap.h leftHeap.h skewHeap.h comparison.cpp minHeap.cpp leftHeap.cpp skewHeap.cpp -o lab10
clean:
rm lab10 *.o
I hope that's not info overload. Please let me know if anyone has any ideas on this. I've looked at the other g++ "does not name a type" issues on here (and a couple of full page of google searches as well) but haven't found anything that may account for this. I have this sneaking suspicion that it may be something simple I've overlooked but any help would be greatly appreciated.
Thanks!
Look at your include guard really carefully: #ifdef LEFTHEAP_H.
This is just a typo (assuming it is transcribed accurately):
#ifdef LEFTHEAP_H
#define LEFTHEAP_H
in leftHeap.h should be #ifndef
#ifndef LEFTHEAP_H
#define LEFTHEAP_H