Can't Access sys/socket.h using Cygwin - linux

I need to compile C/C++ pthread and socket code in windows 8 where I've installed MicGW GCC and G++ 4.7.
When I compile my test code using g++ test.cpp -o test
Code is:
#include<iostream>
#include<sys/socket.h>
#include<sys/types.h>
using namespace std;
int main() {
cout<<"Got Socket";
}
This gives error fatal error: sys/socket.h not found and the
same occur with types.h
The error I found is that cygwin is using MicGW GCC and g++ but I want it to use its own instead of MinGW's so that I can include Linux libraries.

I have not been able to reproduce your problem on my Cygwin.
Are the headers present in /usr/include/sys?

Search the sys folder in [installed directory]/usr/include if the socket.h was not there download one Copy it there manually.
don't afraid of manual works ;-)

Related

Build process crashes with boost and C++11

What I have:
I am writing Qt application for Linux (I work in Linx Mint 17.3 64-bit)
I use C++11 features in my Qt project (Qt ver 5.5)
I want to add libslave to my Qt project.
libslave uses deprecated (for C++11) boost::function, boost::shared_ptr, boost::bind and boost::any.
My trouble:
When I compile with gcc (v the whole project or only library with -std=c++11 flag boost crashes with many errors. Qt Creator shows about 4000 errors, but they are pretty similar and look like:
typedef boost::function< void( RecordSet& )> callback;
is not complete type
BOOST_NOEXCEPT'does not name a type
~any() BOOST_NOEXCEPT
etc...
I have tried to rewrite library with C++11 std library, but std does not containg boost::any analog, so that was bad idea.
Question:
How to compile boost (or at least libslave) with c++11?
Boost Version: 1.54 (from repo)
g++ version: 4.8.4 (from repo)
Qt version: 5.5 (downloaded from Official Site)
Linux Mint: 17.3 Rosa
UPDATE:
Example:
You can download code what I try to compile by this link.
Instruction:
Download tarball
Extract
Go to folder and just type make (all works fine)
Open MakeFile and replace CXX variable to
CXX = g++ -std=c++11
Try to make again and you'll get errors.
P.S.
To compile library you'll need libmysqld-dev, libboost-all-dev, libmysqlclient-dev.
Probably you'll need something else, but I don't remeber. Sorry.
I found the hack and it works for me.
I replace boost::bind usage in file nanomysql.h to std::bind by such strings:
...
typedef std::map<std::string, field> value_t;
typedef std::vector< value_t > result_t;
void store(result_t& out)
{
//You need specify template because of push_back has overloads
auto hack = std::bind<void(result_t::*)(const value_t&)>(&result_t::push_back, &out, _1);
use(hack);
}
...
And replace all boost::shared_ptr, boost::function to std::shared_ptr and std::function in all files in library.
After this everything compiles and work fine with -std=c++11 flag.
Whole code of nanomysql.h you can see here:
Link to code
Use actual fork of libslave - https://github.com/vozbu/libslave with support c++11. Support for mysql 5.6 and 5.7 will be soon

Linux - setting Code::Blocks to compile multithreading C++ code

I have searched through forums here, but nothing helped to the end in my case.
I'm trying to write and compile some C++ multithreading code in Code::Blocks 13.12, for now the only code I have is:
#include <iostream>
#include <thread>
void cpp11()
{
std::cout<<"C++11 MULTITHREADING\n";
}
int main()
{
std::thread t(cpp11);
t.join();
}
Initially I could not compile and run that code (both in Code::Blocks and Terminal) because I was getting an error:
Terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not
permitted.
I found that I'm able to compile and run that code calling g++ in the Terminal like that:
g++ -std=c++11 -pthread main.cpp -o Program
but I cannot set the same in Code::Blocks.
I went to Project -> Build options, in the Compiler settings tab I selected Have g++ follow the C++11 ISO C++ language standard [-std=c++11].
In the Compiler settings -> Other options I typed -pthread.
In Linker settings -> Other linker options I typed -pthread.
It does not work, after I build and run my project in Code::Blocks I get the same error message.
Thank you for any help!
Follow instructions for this question
How do I link to a library with Code::Blocks?
in the last step, when Add library dialog pops up type pthread.
UPDATE
Again go to build options > Compiler settings . click on other options and type -pthread

cross-compiling c++11 threads with mingw on linux

I try to crosscompile some c++11 source with mingw on linux for windows. The code uses std::thread.
When i compile i always get some errors:
$ ../mingw/cross/bin/i686-w64-mingw32-g++ -std=c++11 -I include/ test.cpp -lstdthread -otest
In file included from test.cpp:4:0:
...
error: 'thread' in namespace 'std' does not name a type
...
I it possible to enable c++11 threads in mingw? The code compiles without any problems with the local g++.
Thank you,
regars
Kevin
-edit-
I just downloaded the mingw somewhere in the internet, because i tried to get an as new as possible version:
../mingw/cross/bin/i686-w64-mingw32-g++ -v
Using built-in specs.
COLLECT_GCC=../mingw/cross/bin/i686-w64-mingw32-g++
COLLECT_LTO_WRAPPER=/home/bmeier/source/mingw/cross/bin/../libexec/gcc/i686-w64-mingw32/4.8.1/lto-wrapper
Target: i686-w64-mingw32
Configured with: /home/drangon/work/mingw-w64-dgn_32/source/gcc-4.8.1/configure --target=i686-w64-mingw32 --disable-nls --disable-multilib --with-gmp=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-mpfr=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-mpc=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-isl=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --with-cloog=/home/drangon/work/mingw-w64-dgn_32/build/for_cross --enable-languages=c,c++,objc,obj-c++ --disable-libstdcxx-pch --prefix=/home/drangon/work/mingw-w64-dgn_32/cross --with-sysroot=/home/drangon/work/mingw-w64-dgn_32/cross
Thread model: win32
gcc version 4.8.1 (GCC)
regards
Kevin
There is already a native implementation of std::thread and sync primitives, that works with any C++11 version of MinGW:
https://github.com/meganz/mingw-std-threads
Basically MinGW does not support threads on windows see the following link: http://www.cplusplus.com/forum/windows/82461/
Specifically _GLIBCXX_HAS_GTHREADS is not defined and the class thread in the header thread requires it. (It is built on gthreads).
You should try and use boost::thread for a win/linux compatible thread class
Most probably you might have forgot to include thread header #include <thread>

"Compiler threading support is not turned on."

Normally I can google my way around and find solutions, but not this time.
I'm using 64 bit Linux Ubuntu 11.04 to compile a 32 bit windows application. I'm using i586-mingw32msvc-gcc to compile my C++ files.
test.cpp:
#include <boost/asio.hpp>
makefile:
i586-mingw32msvc-gcc -c -m32 -mthreads -o test.o test.cpp
Error:
boost/asio/detail/socket_types.hpp:
# include <sys/ioctl.h>
doesn't exist.
Added to makefile: -DBOOST_WINDOWS
Error:
# warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately
Ok, added to makefile: -D_WIN32_WINNT=0x0501
Error:
# error "Compiler threading support is not turned on. Please set the correct command line options for threading: -pthread (Linux), -pthreads (Solaris) or -mthreads (Mingw32)"
Yet I did specify -mthreads.
Adding -DBOOST_HAS_THREADS might be sufficient (see # elif defined __GNUC__ from the offending header). But it's likely/possible that your boost installation has been crafted to support your build environment and not your target. Try building it yourself with your cross-compiling toolchain.
It turned out that I had a set of #undef and #defines to force the GLIBC version to something that allowed me to compile for Linux (not cross compile) RHEL5, which otherwise would give me all kinds of other errors. Turns out that when cross compiling for windows using mingw, that force feeding the GLIBC version causes boost to take a strange path leaving various aspects undefined, including the bahavior or availability of threading. I surrounded it with an #ifndef _WIN32 which made the problem go away.
Maybe that -mthreads argument needs to come last.

Setting up G++ or ICC for mpi.h on Ubuntu

I have never done any major programing outside of VS08.
I am trying to compile a program called LAMMPS with either of the two relevant make files. One calls g++ and the other calls icc (Intel's compiler).
icc produces this error:
icc -O -DLAMMPS_GZIP -DMPICH_SKIP_MPICXX -DFFT_FFTW -M write_restart.cpp > write_restart.d
write_restart.cpp(15): catastrophic error: cannot open source file "mpi.h"
#include "mpi.h"
and g++ throws this error
g++ -g -O -DLAMMPS_GZIP -DMPICH_SKIP_MPICXX -DFFT_FFTW -M verlet.cpp > verlet.d
pointers.h:25: fatal error: mpi.h: No such file or directory
compilation terminated.
The mpi.h file is located in /usr/lib/openmpi/include
It is my understanding that I need to set that $PATH variable which reads
bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/opt/intel/bin:/usr/lib/openmpi/include:
and $LD_LIBRARY_PATH which currently reads
/usr/lib/openmpi/lib:
SO, how does one include the mpi.h file? So that either icc or g++ find it?
mpi.h is a header for MPI library. That would be included if you use mpic++ MPI compiler wrapper instead of g++ in your makefile. mpic++ will call the appropriate compiler. From what you describe you have openmpi package installed on your ubuntu machine.
For more info, you need to consult the manual, e.g.
http://lammps.sandia.gov/doc/Section_start.html#2_2 (for LAMMPS)
and perhaps you need to see openmpi manual as to how to set up additional compiler. Not sure if this can be done after openmpi itself has been built. By default I think in Ubuntu openmpi compiler wrappers would only call g++. CMIIW.
Okay, so I got it to work with g++ when setting up cc as "mpic++.mpich2" instead of "mpic++"
you can try compile using openmpi make file in /src/MAKE
make openmpi
in my case, this option was successful

Resources