tags:

views:

687

answers:

6

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?
+2  A: 

Yes, Yes, Yes, Yes (if you write it carefully and don't use anything specific to cygwin), No.

On 5: it may be possible to cross-compile from Cygwin to Linux, I really don't know. If it is, then technically some executables "built by Cygwin" would run on Linux. But Cygwin executables won't run on Linux.

Steve Jessop
+3  A: 

"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.

moonshadow
+1  A: 

In response to #7, the version of the C++ compiler that you have is probably out of date. If you don't need linux/posix portability, I'd switch to the non-cygwin MinGW GCC compiler - you can get 4.4.1 at http://tdragon.net/recentgcc/

anon
I use gcc 4 in Cygwin
SjB
+1  A: 

Regarding 6, you don't need -lpthread because Pthreads support is part of the Cygwin DLL.

ak
Thanks nice answer
SjB
+12  A: 

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.

ConcernedOfTunbridgeWells
for use QT in cygwin which package must install ?
SjB
qt4-* - see the edit.
ConcernedOfTunbridgeWells
Thanks nice answer in QT !
SjB
+2  A: 

1-4: The answers to these are all "yes", because all of these features you are asking about are part of the POSIX standard. Cygwin is basically a POSIX layer for Windows so, naturally, Cygwin includes all of these features.

5: No, Cygwin binaries will not execute under the Linux kernel, because ultimately the code generated by Cygwin is Windows native code. It will link with the usual Windows DLLs (like kernel32.dll), whereas Linux does not even have a notion of DLLs (it has shared objects which are similar, but different). More importantly, executables built under Cygwin will be in the PE format, but Linux generally uses the ELF format for executables. You could, of course, do cross-compiling under Cygwin, and thereby generate native Linux executables, but it doesn't sound like this is what you are looking for. Also, compiling a new version of GCC to use as a cross-compiler under Cygwin is probably no trivial task.

6: GCC under Cygwin doesn't require use of -lpthread because all of the pthread code under Cygwin is in cygwin1.dll which is always linked in by default.

7: This is a bug in GCC (on all platforms). It has been around for a long time and will probably never be fixed.

8: ConcernedOfTunbridgeWells did a great job of explaining this, so there's not much left for me to say. However, it's worth noting that Cygwin has the X.org X Window System in its package list. With Cygwin 1.7.x, setting it up and using it is a breeze and it seems pretty rock-solid. If you want to use Qt with X, I'd recommend using Cygwin's X server.

Dan Moulding
+1 for a cogent answer to #7, although Xming is a better general purpose X server than the standard Cygwin one. IMO XMing is nearly as good as Starnet.
ConcernedOfTunbridgeWells