Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Some Issues About Cygwin[Linux in Windows] (socket,thread,other programming and shell issues)

Tags:

c++

c

linux

cygwin

I have some question about cygwin :

  1. Can I use Cygwin develop socket based code?
  2. Does Cygwin have read() and write() functions that work with file descriptors?
  3. Can I use Pthread library in Cygwin?
  4. Does code that compiles in Cygwin also compile in Linux without any change or with little change?
  5. Will an executable file that built by Cygwin run in Linux ?
  6. Why does Cygwin not need the linker option -lpthread when I use pthread library?
  7. why in #include <iostream> don't I need to use using namespace std; ?
  8. Can I work with QT in Cygwin? If so,How?
  9. Can I boot my Linux in other
  10. partition with Cygwin and use it?
  11. Can I access the other partition that is EXT3 in Cygwin?
like image 411
Sajad Bahmani Avatar asked Jan 18 '10 16:01

Sajad Bahmani


People also ask

What is Cygwin used for?

Cygwin is a collection of open source tools that allows Unix or Linux applications to be compiled and run on a Microsoft Windows operating system (OS) from within a Linux-like interface. Cygwin offers users a Linux-like experience in a Windows environment.

What does Cygwin include?

Cygwin consists of a library that implements the POSIX system call API in terms of Windows system calls to enable running of a large number of application programs equivalent to those on Unix systems, and a GNU development toolchain (including GCC and GDB) to allow software development.

What is Cygwin and MinGW?

Cygwin uses a DLL, cygwin. dll, (or maybe a set of DLLs) to provide a POSIX-like runtime on Windows. MinGW compiles to a native Win32 application. If you build something with Cygwin, any system you install it to will also need the Cygwin DLL(s). A MinGW application does not need any special runtime.

Is Cygwin secure?

Cygwin is safe for all practical purposes. It's an executable, and it downloads a bunch of applications compiled for cygwin.


2 Answers

On 1: Yes. Socket libraries are shipped with Cygwin - many socket based apps such as web servers are included in the base distribution.

On 2: Yes. I think all of the 'section 2 and 3' system calls in the GNU C runtime and library are implemented by the cygwin runtume. You can check this in the man pages that come with Cygwin. A list of system calls and std lib calls implementd by Cygwin can be found here.

On 3: Yes. Pthread is included in Cygwin. The list referred to in the link above mentions pthreads as well.

On 4: Anything built against GNU libraries should work with little or no change between Cygwin and Linux (assuming there are no dependencies missing on Cygwin). Depending on CPU architecture you may have to worry about word alignment, endianness and other architecture-specific porting issues, but if you're targeting Windows and Linux on Intel your code would have few if any porting issues arising from CPU architecture.

On 5: Cygwin will build a program against its own shared libraries by default but GCC can cross-compile to target other platforms. You could (in theory) set GCC up to cross-compile to any target supported by the compiler. There are plenty of resources on the web about cross-compiling with GCC, and I don't think the process will be materially different on Cygwin.

Note that Cygwin binaries will not run on Linux - or Vice-versa. You will still need separate builds for both.

On 6: Not sure - at a guess it's included in the standard runtime, perhaps because it was necessary to wrap the Win32 threading API for some reason.

On 7: Don't know - it's probably the same on g++ on all platforms. Apparently a compiler bug. Dan Moulding's Answer covers this in more detail.

On 8: Yes. IIRC QT is available in the standard builds and it will certainly compile on Cygwin. As with Linux/Unix, QT on Cygwin uses an X11 backend so you will need to have an X server such as XMing running.

In order to avoid the dependency on an X server you may want to build QT apps against the Win32 API,. It is possible to do this with MinGW, which is a set of header files and libraries to build native Win32 apps with GCC. MinGW can be used from within a Cygwin environment (an example of GCC on Cygwin cross-compiling to a non-Cygwin target) and the installer from cygwin.com gives you the option of installing it.

MinGW is quite mature; it has all of the 'usual suspects' - libraries and header files you would expect to find on a Unix/Linux GCC development environment and is very stable. It is often the tool of choice for building Win32 ports of open-source software because it is (a) free, (b) supports the libraries used by the software and (c) uses GCC so it is not affected by dialectic variations between MSVC and GCC.

However, these dialectic variations in the language and available libraries (for example MSVC doesn't come with an implementation of getopt) mean that porting programs between MinGW and MSVC can be quite fiddly. My experience - admittedly not terribly extensive as I've only done this a few times - is that porting applications between MinGW32 and Linux is easier than porting between MinGW and MSVC. Obviously apps with non-portable dependencies such as Win32 specific API usage would require the dependent components to be re-written for the new platform but you'll have far fewer problems with differences in the standard libs, header files and language dialect.

QT does a fairly good job of providing a platform abstraction layer. It provides APIs for database access, threading, I/O and many other services as well as the GUI. Using the QT APIs where possible should help with portability and the Unix/Linux flavoured libraries that come with MinGW mean that it might give you a good platform for making applications that will port between Win32 and Linux with relatively little platform dependent code.

EDIT: The qt development packages in Cygwin are:

  • qt4: Qt application framework (source)
  • qt4-devel-tools: Qt4 Assistant, Designer, and Linguist
  • qt4-doc: Qt4 API documentation
  • qt4-qtconfig: Qt4 desktop configuration app
  • qt4-qtdemo: Qt4 demos and examples

You'll probably also need gcc4-g++ and some other bits and pieces. This listing on the cygwin web site has a list of the packages.

like image 67
11 revs Avatar answered Oct 09 '22 20:10

11 revs


"Yes" to all of those except 5. You'll have to build your executables separately for Linux, but that should be straightforward since the answer to 4 is "yes".

Make sure you install all the development headers you need on both platforms.

like image 23
moonshadow Avatar answered Oct 09 '22 20:10

moonshadow