How to use websocketpp with C++? - c++

I'm pretty new to WebSocket in C++ and trying to use websocketpp library from Github https://github.com/zaphoyd/websocketpp. Since as I said I'm new I still not able to figure out how to use it. I'm trying to run some sample WebSocket program from the same sample repo.
Can someone please tell me in detail how to use it. I have cloned the repo in my local system and compiling this sample file
#include <iostream>
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
typedef websocketpp::server<websocketpp::config::asio> server;
void on_message(websocketpp::connection_hdl hdl, server::message_ptr msg)
{
std::cout << msg->get_payload() << std::endl;
}
int main()
{
server print_server;
print_server.set_message_handler(&on_message);
print_server.init_asio();
print_server.listen(9002);
print_server.start_accept();
print_server.run();
}
throw the error fatal error: websocketpp/config/asio_no_tls.hpp: No such file or directory
#include <websocketpp/config/asio_no_tls.hpp>
moreover seraching the error button it shows includePath error.
Help me out. Thanks alot in advance.

I guess you get this error because you didn't add this header file to include directories and library directories parts of your project.
Right click on project and select Properties.
Common Properties => VC++ Directories
Include Directories => add the directory where you installed websocketpp library.
Library Directories => add the directory where you built websocketpp library.

Related

Unable to use libpqxx library with header <pqxx/pqxx> on XCode

I am trying to use libpqxx library.
I have installed the library and it's under the below path on my machine-
/opt/homebrew/Cellar/libpqxx/
I have also updated search paths as below under Build Settings on Xcode -
Header Search Paths - /opt/homebrew/Cellar/libpqxx/**
Library Search Paths - /opt/homebrew/Cellar/libpqxx/**
For more details check below snapshot -
Search Paths
Have updated Linker Flags under build settings as -
Other Linker Flags -> -lpqxx
For more details check below snapshot -
Linker Flags
However when I compile main.cpp file using header -
#include <pqxx/pqxx>
It throws below error, count of errors = 50, reports below error for all namespaces or classes in library libpqxx-
error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
Need advice to overcome this.
Sample Program -
#include <iostream>
#include <pqxx/pqxx>
#include <string>
using namespace std;
int main() {
try {
// Connect to the database
pqxx::connection; c("user=postgres password=xxxx#123 host=localhost port=5432 dbname=postgres target_session_attrs=read-write");
}
catch (const exception &e) {
cerr << e.what() << endl;
return 1;
}
}
Explanation -
I see compiler reported almost 50 errors, i believe for each class or namespace under libpqxx library. I certainly can't add every header individually, I need help in understanding how to make the header alone when used like # include<pqxx/pqxx> to compile successfully
Any inputs on this will be highly appreciated.

Fatal Error: comdef.h: No such file or directory

I installed Aspose.Cells and tried to write a simple C++ file that includes Aspose.Cells.h. I soon realized that I had to install two other external libraries, boost and icu4c as without these libraries my compiler would throw errors saying some h or hpp files can not be found.
My problem is: even after I installed these libraries, I still couldn’t compile my code, as I received a new error saying “Fatal ERROR: comdef.h: No such file or directory.”
And the error persisted even after I installed the latest version for SDK for Win 10.
My simple file can run if I remove the line "#include Aspose.Cells.h" .
Can someone please enlighten me as to how to solve this error?
Also I noticed there is a folder called “Publish” under “include” folder for Aspose.Cells. This folder is besides boost and icu. Could this mean Publish is the third external library to be installed? But I couldn’t find any library called Public on the web. Pls see the screenshot below.
directory of include folder that comes with the installed Aspose.Cells package
Thanks a lot!
My code is as follows:
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "hello!!!" << endl;
return 0;
}
Regards
Hillary

FATAL ERRORS with compilation after installing Aspose.Cells library for C++

Can someone please help me with my issue with Aspose.Cells library for C++?
I was writing my first C++ programme using Aspose.Cells library. Everything seemed smooth except that the following error was produced after I built the file:
Error before I launch is:
"Error exist in a required project.Continue launch?"
Error after running the code is:
"**fatal error: boost/config/compiler/gcc.hpp: No such file or directory**".**
If I commented out the line #<include Aspose.Cells.h>, the file can run with no errors.
I tried to solve the error by installing Boost library for C++ from zip file "boost_1_73_0", as I think Aspose depends on Boost to run. However, I couldn't link to Boost successfully as there doesn't seem to be a "include" folder and "lib" folder for me to add into project properties.
My questions are:
Will installing Boost solve my problem?
If yes, how can I install Boost library successful?
The following is my code in C++. Thanks a Lot in advance!
#include <iostream>
#include <Aspose.Cells.h>
using namespace std;
int main() {
cout << "!!!I am little red!!!" << endl;
return 0;
}
Regards
Hillary
UPDATE: I have successfully installed and linked Boot library now but I have got three warning message upon building: "Ignoring #pragma warning [-wunknown-pragmas]" , are these warning messages serious?
I also ran into another fatal error: unicode/uloc.h:No such file or directory. How can I correctly link up to unilib-master/Unicode library?
Yes, installing Boost helps.
If Aspose only requires header-only libraries from Boost, then you don't have to do much. The "include" path you're looking for is just the folder where you extracted the zip. The actual library headers are under boost/ in that folder, which are then found by the compiler.
If you need the shared libraries, you will need to build them. Follow the steps here Getting Started On Windows

cannot open include file 'Graphics.hpp' no such file or directory ,additional include for visual studio not working

i m trying to use sfml in my project using visual studio 2019. Following sfml documentation to perform setup for visual studio i have performed all the action required
i have included include folder in c/c++/additional include directory and also provided path for lib folder in linker setting and also provided additional dependencies in linker/input
but
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
std::cout << "i cant tolerate" << std::endl;
return 0;
}
this code shows above mentioned error ,
cannot open include file 'Graphics.hpp' no such file or directory
it seems like include path is not working
how can i solve this issue
i tried many times but got same result
if anyone facing the same problem please check the platform in the project/properties win32 worked for my particular problem

Error C1083: Cannot open source file: "stdafx.cpp': No such file or directory

I have the above error and have followed all solutions but does not fix.
This is my stdafx.h file. I have it in the target directory, I can see the file and the full path goes to there. In addition, I have created a win32 project. Why is my code not working?
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
ACTUAL CODE:
// ConsoleApplication1.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>
int main() { std::cout << "Hello world!" << std::endl; return 0; }
For the record, I had this problem when cloned a repo using git from the Ubuntu shell in Windows 10.
After I cloned the repo to a different location usin git from a Windows shell, the problem went away and the solution builds fine.
The issue was that the build scripts were looking for 'stdafx.cpp' in a folder with uppercase name (C:\GIT\LIBRARYX\SRC\) and this path did not work if the solution was cloned using git from Ubuntu bash.