How to use boost asio library with Cygwin 64 bit - c++

I am running Windows 10 64bit. Cygwin is 64 bit.
I installed boost from cygwin package manager.
I tried to compile test.cpp:
#include <boost/asio.hpp>
int
main(int argc, char**argv)
{
return 0;
}
using command
g++ -std=c++11 -Wall -g -D__USE_W32_SOCKETS D_WIN32_WINNT=_WIN32_WINNT_WIN7 test.cpp -o test.exe
but compile fails. It looks like posix is being used.
Any ideas why this fails?
In file included from /usr/include/boost/asio/detail/fd_set_adapter.hpp:22:0,
from /usr/include/boost/asio/detail/select_reactor.hpp:27,
from /usr/include/boost/asio/detail/reactor.hpp:29,
from /usr/include/boost/asio/detail/impl/task_io_service.ipp:24,
from /usr/include/boost/asio/detail/task_io_service.hpp:198,
from /usr/include/boost/asio/impl/io_service.hpp:71,
from /usr/include/boost/asio/io_service.hpp:767,
from /usr/include/boost/asio/basic_io_object.hpp:19,
from /usr/include/boost/asio/basic_socket.hpp:20,
from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
from /usr/include/boost/asio.hpp:21,
from appcontrol.cpp:16:
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp:82:12: error: 'fd_set' does not name a type
operator fd_set*()
^
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp:105:11: error: 'fd_set' does not name a type
mutable fd_set fd_set_;
^
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp: In constructor 'boost::asio::detail::posix_fd_set_adapter::posix_fd_set_adapter()':
/usr/include/boost/asio/detail/posix_fd_set_adapter.hpp:42:14: error: 'fd_set_' was not declared in this scope
FD_ZERO(&fd_set_);
^

Thanks to help from #cygwin IRC:
g++ -std=c++11 -Wall -g -D_XOPEN_SOURCE=500 test.cpp -o test.exe -lboost_system

Related

g++ won't compile very simple program using threads

Attempting to use threads in C++ for the first time. Here is my code:
#include <iostream>
#include <thread>
int main(){
std::thread th;
}
To compile, I am using:
g++ -g -Wall -std=c++11 -pthread threadtest.cpp
This gives the following error:
$ g++ -g -Wall -std=c++11 -pthread threadtest.cpp
threadtest.cpp: In function 'int main()':
threadtest.cpp:5:8: error: 'thread' is not a member of 'std'
5 | std::thread th;
| ^~~~~~
threadtest.cpp:3:1: note: 'std::thread' is defined in header '<thread>'; did you forget to
'#include <thread>'?
2 | #include <thread>
+++ |+#include <thread>
3 |
If I comment out the "std::thread th" line, the error message changes to:
$ g++ -g -Wall -std=c++11 -pthread threadtest.cpp
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
Operating system: Windows 10. Seems to get the same result whether I'm using the plane-old windows command line or if I do it in Cygwin. Anyone know what's wrong? Thanks in advance.

QueryFullProcessImageName was not declared in this scope

Build settings
Included #include <windows.h> and #include <Psapi.h> but I keep getting this error.
g++ -O3 -Wall -c -fmessage-length=0 -o main.o "..\\main.cpp"
..\main.cpp: In function 'int main()':
..\main.cpp:27:64: error: 'QueryFullProcessImageName' was not declared in this scope
if (QueryFullProcessImageName(hProcess, 0, buffer, &buffSize)) {
You were probably using classic MinGW, which is quite outdated.
Please use the more up to date MinGW-w64, which exists for both Windows 32-bit and 64-bit.
A recent version can be installed via MSYS2's package manager or you can get a standalone version from https://winlibs.com/.

Compile pthread.h stuff on AIX using g++

I try to compile this very simplified program:
#include <pthread.h>
int main(){
pthread_yield();
return 0;
}
using -pthread like the IBM side says:
$ g++ -pthread test.cpp -o test
and get this error:
test.cpp: In function 'int main()':
test.cpp:4:15: error: 'pthread_yield' was not declared in this scope
pthread_yield();
I tried lots of other falgs too, but nothing worked so far. The pthread.h is in /usr/includes but pthread_yield() needs _AIX_PTHREADS_D7 defined.
Do I have to define this myselfe or is this done by adding some flag?
THX!
Other than defining symbol _AIX_PTHREADS_D7 you have to use library libpthreads_compat as well.
g++ -o marscode marscode.cc -D_AIX_PTHREADS_D7 -lpthreads_compat -lpthreads

Code compiles on g++ with warning but gives error for same code on clang3.1(Xcode 4.3.3)

Following line compiles successfully on g++ but gives error on clang::
static_assert(tBits <= sizeof(ULONG)*8, "This is IO method");
g++ warning ::
there are no arguments to 'static_assert' that depend on a template parameter, so a declaration of 'static_assert' must be available
clang error ::
use of undeclared identifier 'static_assert'; did you mean 'static_cast'?
please help me out.
Function declaration from comment:
template < size_t tBits >
HRESULT DoIO( std::bitset< tBits >& bitsetToSerialize ) const
"static_assert" was introduced in C++11 as a language keyword - not a function or a macro.
Both compilers are giving you the "I don't know this function" warnings/errors.
For the compiler to give you "I don't know this function" when you are using "static_assert", the compiler must not be compiling with C++11 support (-std=c++11).
To demonstrate this, I took the following piece of code:
#include <bitset>
template<size_t tBits>
int DoIO(std::bitset<tBits>& /*bitsetToSerialize*/)
{
static_assert(tBits <= sizeof(unsigned long) * 8, "tBits is too big.");
return tBits;
}
Then I compiled it with GCC 4.7.3 and I got the following error:
osmith#olivia64 ~/src $ g++ -o sa.o -c sa.cpp
sa.cpp: In function ‘int DoIO(std::bitset<_Nb>&)’:
sa.cpp:6:78: error: there are no arguments to ‘static_assert’ that depend on a template parameter, so a declaration of ‘static_assert’ must be available [-fpermissive]
sa.cpp:6:78: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
Then I compiled it with C++11 support enabled and it compiled without a problem:
osmith#olivia64 ~/src $ g++ -std=c++11 -o sa.o -c sa.cpp -Wall
osmith#olivia64 ~/src $
So, then I compiled it with Clang
osmith#olivia64 ~/src $ clang++ -o sa.o -c sa.cpp
sa.cpp:6:9: error: use of undeclared identifier 'static_assert'; did you mean 'static_cast'?
static_assert(tBits <= sizeof(unsigned long) * 8, "tBits is too big.");
^
1 error generated.
and finally I compiled it using Clang with C++11 support, where it compiled fine.
osmith#olivia64 ~/src $ clang --version
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
osmith#olivia64 ~/src $ clang++ -std=c++11 -o sa.o -c sa.cpp
osmith#olivia64 ~/src $
Just to be sure, let's give the compiler opportunity to help us and turn on "-Wall":
osmith#olivia64 ~/src $ g++ -Wall -o sa.o -c sa.cpp
sa.cpp:6:9: warning: identifier ‘static_assert’ is a keyword in C++11 [-Wc++0x-compat]
sa.cpp: In function ‘int DoIO(std::bitset<_Nb>&)’:
sa.cpp:6:78: error: there are no arguments to ‘static_assert’ that depend on a template parameter, so a declaration of ‘static_assert’ must be available [-fpermissive]
sa.cpp:6:78: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)

atomic_thread_fence is not a member of std

Compiling with:
g++ -std=c++0x -Wall -pthread test2.cc -o hello
I'm getting this error:
test2.cc: atomic_thread_fence is not a member of std
I am using g++ 4.5.2 in Ubuntu. What am I missing?
Do you have the following in test2.cc?
#include <atomic>