boost::asio::ssl::context crash during construction - c++

I can't figure why the following instruction crashes:
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12);
I got the following error: Process returned -1073741819 (0xC0000005)
There is nothing more to catch regarding exceptions and AFAIK the boost documentation doesn't mention incompatibility issues between the boost and openssl versions.
my environment:
gcc from cygwin: C:\cygwin64\x86_64-w64-mingw32-g++.exe
linker options: -lws2_32 -lcrypto -lssl
using boost 1.78 (dl from website) and cygwin's openssl 1.1.1m packages
here is the minimal example:
#include <iostream>
#include <boost/asio/ssl/context.hpp>
int main()
{
std::cout << "before" << std::endl;
try {
boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12);
} catch (...) {
std::cout << "catch" << std::endl;
}
std::cout << "after" << std::endl;
return 0;
}
output:
before

The openssl cygwin package I installed is not a stable one, so the include and lib files are missing and I'm using the wrong ones (incompatible with the x86_64-w64-mingw32-g++ compiler). I've installed another stable version and the desired files are available now.

Related

“Program received signal SIGABRT, Aborted.“error in remote Linux,why? [duplicate]

I created and executed a simple thread on my system. when I execute this program, I have the error message : Enable multithreading to use std::thread: Operation not permitted
some details about my system :
linux ubuntu 13.10
g++ 4.8.1
I compile the source code including the library pthread
The source code:
#include <iostream>
#include <thread>
using namespace std;
void func(void) {
cout << "test thread" << endl;
}
int main() {
cout << "start" << endl;
thread t1 (func);
t1.join();
cout << "end" << endl;
return 0;
}
It seems that you are trying to use C++11 threads. If it is true, then
correct #include <thread> and #include <iostream>, i.e. do not use " in these lines and add # in front of them.
compile with g++ -std=c++11 q.cpp -lpthread (dependency order matters for newer g++)
Hint: when you are using threads in a static linked library and use this library in an executable, then you have to add the flag -pthread to the link command for the executable. Example:
g++ Obj1.o Obj2.o MyStaticLib.a -o MyExecutable -pthread

Where does Homebrew install C++ packages?

I would like to use C++'s std::format library to format strings. See the minimal working example below.
/* example.cpp */
#include <iostream>
#include <format>
#include <string>
int main() {
std::string s = std::format("Hello, {}!", "John");
std::cout << s << std::endl;
return 0;
}
However, when I compile my code, I get the following error message:
example.cpp:2:10: fatal error: format: No such file or directory
2 | #include <format>
I am using the latest version of macOS, and I have Homebrew installed as my package manager. I already installed clang-format through Homebrew, but for some reason, my compiler can't locate the header file. Can somebody help me figure out the problem is? I have tried using Apple's GCC and the custom GCC10 provided by Homebrew, but in both cases, I get the same error message. Is this a Homebrew issue or a C++ issue?
Following this answer to use fmt, you can install the library with brew install fmt, then modified the code to
/* example.cpp */
#include "fmt/format.h"
#include <iostream>
#include <string>
int main() {
std::string s = fmt::format("Hello, {}!", "John");
std::cout << s << std::endl;
return 0;
}
and compile with
clang++ -std=c++11 test.cpp -lfmt

Possible bug with DirectoryIterator

Working with DirectoryIterator example, from Poco documentation, I have some issues with it.
This is the source code:
#include "Poco/DirectoryIterator.h"
#include <iostream>
using Poco::DirectoryIterator;
using Poco::Path;
int main(int argc, char** argv) {
std::string cwd(Path::current());
DirectoryIterator it(cwd);
DirectoryIterator end;
while (it != end) {
std::cout << it.name();
if (it->isFile())
std::cout << it->getSize();
std::cout << std::endl;
Path p(it.path());
++it;
}
return 0;
}
I am using Mingw, with gcc 8.2, under Msys2 and Windows 7 (tested with Windows 10 too). Using Eclipse CDT as IDE.
When compiling in Debug mode, and run the binary, the exception "Path not found" is thrown.
When compiling in Release mode, and run the binary, it works, but the iterator "it" doesn't evolve.
It always shows "a.txt"
I am trying the example with this directory tree:
/test//a.txt
/test//b.txt
/test//test2
/test/test2/c.txt
/test/test2/d.txt
I have tested the same example in linux, and everything is working ok.
Why does it work in Linux, but not in Windows?
Any clue?
Thanks
Compiling your program, I get the next message: "Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated"
You need to compile with #define POCO_WIN32_UTF8.
#define POCO_WIN32_UTF8
#include "Poco/DirectoryIterator.h"

Thread doesn't work with an error: Enable multithreading to use std::thread: Operation not permitted

I created and executed a simple thread on my system. when I execute this program, I have the error message : Enable multithreading to use std::thread: Operation not permitted
some details about my system :
linux ubuntu 13.10
g++ 4.8.1
I compile the source code including the library pthread
The source code:
#include <iostream>
#include <thread>
using namespace std;
void func(void) {
cout << "test thread" << endl;
}
int main() {
cout << "start" << endl;
thread t1 (func);
t1.join();
cout << "end" << endl;
return 0;
}
It seems that you are trying to use C++11 threads. If it is true, then
correct #include <thread> and #include <iostream>, i.e. do not use " in these lines and add # in front of them.
compile with g++ -std=c++11 q.cpp -lpthread (dependency order matters for newer g++)
Hint: when you are using threads in a static linked library and use this library in an executable, then you have to add the flag -pthread to the link command for the executable. Example:
g++ Obj1.o Obj2.o MyStaticLib.a -o MyExecutable -pthread

BOOST_THROW_EXCEPTION causing Abort Trap

I'm trying to use boost::exception and have condensed my prototype code down to the example in the Boost exception tutorial however when running the code with the BOOST_THROW_EXCEPTION macro I get an abort from the program.
#include <iostream>
#include <boost/exception/all.hpp>
typedef boost::error_info<struct tag_my_info,int> my_info;
struct my_error: virtual boost::exception, virtual std::exception { };
void f() {
BOOST_THROW_EXCEPTION(my_error() << my_info(42));
// Uncomment the below (and comment the above) for the program to work
//throw my_error() << my_info(42);
}
int main(int argc, char** argv) {
try {
f();
}
catch(my_error& x) {
if(int const* mi = boost::get_error_info<my_info>(x)) {
std::cout << "My info: " << *mi << std::endl;
}
}
return 0;
}
Running the code with the BOOST_THROW_EXCEPTION macro:
$ ./a.out
Abort trap
If as the comment says, I swap the code, all is well
$ ./a.out
My info: 42
Below is the output from the g++ preprocessor for f()
void f() {
::boost::exception_detail::throw_exception_(my_error() << my_info(42),__PRETTY_FUNCTION__,"main.cpp",14);
}
Software versions are:
$ g++ -v
Using built-in specs.
Target: x86_64-apple-darwin10
Thread model: posix
gcc version 4.4.6 (GCC)
$ port list boost
boost #1.47.0 devel/boost
I'm on OSX SL using the tools provided by MacPorts. I've double checked the g++ search paths and there's only one copy of the boost hpp files and that's the ones that belong to the aforementioned boost package.
I have no idea why the abort trap is being called. I admit I'm newish to C++ .
The problem was caused by using the MacPorts version of g++. There are plenty of tickets related to exceptions and Abort Traps in the MP system (and plenty of examples on Google).
Using the version of g++ that comes with XCode enabled this problem to go away.