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.
Related
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.
I'm trying to use boost libraries in my C++ application. I'm trying to compile it using g++ with different options.e.g g++ -I /usr/include/boost/filesystem/ -o test.out test.cpp however it always prompt error: 'boost' has not been declared.
And here is my code:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
using namespace std;
int main (){
string line;
string fileName = "Read.txt";
ifstream file;
string str;
file.open(fileName.c_str());
cout << "Hello, world!\n";
vector<string> fileLines;
fileLines.clear();
while (getline(file, str))
{
fileLines.push_back(line);
}
cout << "Total Line count:"<<fileLines.size()<<endl;
fileLines.clear();
cout << "Total Line count:"<<fileLines.size()<<endl;
boost::filesystem::path p("/tmp/foo.txt");
return 0;
}
I will be glad if you help me to fix this.
P.S. I'm compiling my application in Centos 4.7 and It contains Boost version 1.32 according to /usr/include/boost/version.hpp
Update:
I also commented boost instruction, but there is some problem with includes: boost/filesystem.hpp: No such file or directory.
It sounds like you have not yet installed the boost header files that you need for includes. Since you are on CentOS, you need to:
yum install boost-devel
That will place the header file you want in:
/usr/include/boost/filesystem/path.hpp
Since you are using boost::filesystem::path, you should change your #include <boost/filesystem.hpp> to #include <boost/filesystem/path.hpp>. Since -I /usr/include is passed to gcc by default, you do not need the -I /usr/include/boost/filesystem, unless you changed the include to path.hpp. However, this would be dangerous because another library may have the same header file name and then you may include the wrong header.
You can try:
g++ -std=c++11 -Os -Wall -pedantic test.cpp -lboost_system -lboost_filesystem -o test
I had the same problem
Let me know if is works
best regards,
Accodring to header files in my Centos Linux, I changed
#include <boost/filesystem.hpp>
to
#include <boost/filesystem/path.hpp>
And also compiled my program with special link options:
g++ test.cpp -o test.out -lboost_filesystem
I want to compile program with one file test.cpp, which use external library (i have dll and lib). How to do that?
My test.cpp
#include <ExternalLib.h>
#include <iostream>
#include <stdio.h>
#define USE_USB_AUTO_CONNECT 1
int main()
{
printf ("Characters: %c %c \n", 'a', 65);
return 0;
}
ExternalLib is provided by third part company with files: ExternalLib.lib and ExternalLib.dll. There are also files with extension so and a.
When I compile with command:
g++ test.cpp
I get error:
test.cpp:1:20: fatal error: ExternalLib.h: No such file or directory
#include <ExternalLib.h>
Thanks for your help.
I think you are trying to use dll files (compiled in Windows) under Linux, that will not work.
Anyway your error is that the compiler isn't able to locate your header file, to solve this you have several options:
1) Provide the include path when compiling using -I switch
i.e.: g++ test.cpp -I<path to your include directory>
2) Copy the ExternalLib.h to the same directory in which test.cpp lies and use #include "ExternalLib.h" instead of #include <ExternalLib.h>
3) Provide relative path to ExternalLib.h starting from the directory in which test.cpp lies. That is, replace #include <ExternalLib.h> for #include "../../external/ExternalLib.h"
This will solve the No such file or directory problem. Then you will also have to provide the binary/library files using -L (for library path) and -l (for library file) switches.
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!
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