简体   繁体   English

关于Cygwin的一些问题[Windows中的Linux](套接字,线程,其他编程和shell问题)

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

I have some question about cygwin : 我对cygwin有一些疑问:

  1. Can I use Cygwin develop socket based code? 我可以使用Cygwin开发基于套接字的代码吗?
  2. Does Cygwin have read() and write() functions that work with file descriptors? Cygwin是否具有与文件描述符一起使用的read()write()函数?
  3. Can I use Pthread library in Cygwin? 我可以在Cygwin中使用Pthread库吗?
  4. Does code that compiles in Cygwin also compile in Linux without any change or with little change? 在Cygwin中编译的代码是否也在Linux中编译而没有任何更改或几乎没有变化?
  5. Will an executable file that built by Cygwin run in Linux ? Cygwin构建的可执行文件是否会在Linux中运行?
  6. Why does Cygwin not need the linker option -lpthread when I use pthread library? 当我使用pthread库时,为什么Cygwin不需要链接器选项-lpthread
  7. why in #include <iostream> don't I need to use using namespace std; 为什么在#include <iostream>我不需要using namespace std; ?
  8. Can I work with QT in Cygwin? 我可以在Cygwin中使用QT吗? If so,How? 如果是这样,怎么样?
  9. Can I boot my Linux in other 我可以在其他地方启动我的Linux吗?
  10. partition with Cygwin and use it? 用Cygwin分区并使用它?
  11. Can I access the other partition that is EXT3 in Cygwin? 我可以在Cygwin中访问另一个EXT3分区吗?

On 1: Yes. 1:是的。 Socket libraries are shipped with Cygwin - many socket based apps such as web servers are included in the base distribution. 套接字库随Cygwin一起提供 - 许多基于套接字的应用程序(如Web服务器)都包含在基本发行版中。

On 2: Yes. 2:是的。 I think all of the 'section 2 and 3' system calls in the GNU C runtime and library are implemented by the cygwin runtume. 我认为GNU C运行时和库中的所有'第2和第3部分'系统调用都是由cygwin runtume实现的。 You can check this in the man pages that come with Cygwin. 您可以在Cygwin附带的手册页中查看。 A list of system calls and std lib calls implementd by Cygwin can be found here. 可以在此处找到Cygwin实现的系统调用和std lib调用的列表

On 3: Yes. 3:是的。 Pthread is included in Cygwin. Pthread包含在Cygwin中。 The list referred to in the link above mentions pthreads as well. 上面链接中提到的列表也提到了pthreads。

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). 4:任何针对GNU库构建的东西都应该在Cygwin和Linux之间很少或没有变化(假设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. 根据CPU架构,您可能不得不担心字对齐字节序以及其他特定于体系结构的移植问题,但如果您的目标是基于英特尔的Windows和Linux,那么如果有任何移植问题,则代码将很少。

On 5: Cygwin will build a program against its own shared libraries by default but GCC can cross-compile to target other platforms. 5: Cygwin默认会针对自己的共享库构建一个程序,但GCC可以交叉编译以定位其他平台。 You could (in theory) set GCC up to cross-compile to any target supported by the compiler. 您可以(理论上)将GCC设置为交叉编译到编译器支持的任何目标。 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. 网上很多关于与GCC交叉编译的资源 ,我不认为这个过程在Cygwin上会有实质性的不同。

Note that Cygwin binaries will not run on Linux - or Vice-versa. 请注意,Cygwin二进制文件不能在Linux上运行 - 反之亦然。 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. 6:不确定 - 猜测它是否包含在标准运行时中,可能是因为由于某种原因需要包装Win32线程API。

On 7: Don't know - it's probably the same on g++ on all platforms. 7: 不知道 - 在所有平台上的g ++上可能都是一样的。 Apparently a compiler bug. 显然是编译器错误。 Dan Moulding's Answer covers this in more detail. Dan Molding的答案更详细地介绍了这一点。

On 8: Yes. 8:是的。 IIRC QT is available in the standard builds and it will certainly compile on Cygwin. IIRC QT在标准版本中可用,它肯定会在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. 与Linux / Unix一样,Cygwin上的QT使用X11后端,因此您需要运行XMing等X服务器。

In order to avoid the dependency on an X server you may want to build QT apps against the Win32 API, . 为了避免依赖于X服务器,您可能希望针对Win32 API构建QT应用程序 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执行此操作, MinGW是一组头文件和库,用于使用GCC构建本机Win32应用程序。 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可以在Cygwin环境中使用(Cygwin交叉编译到非Cygwin目标的GCC示例), cygwin.com安装程序为您提供安装它的选项。

MinGW is quite mature; MinGW非常成熟; 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. 它拥有所有“常见的嫌疑人” - 您希望在Unix / Linux GCC开发环境中找到的库和头文件,并且非常稳定。 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. 它通常是构建开源软件的Win32端口的首选工具,因为它是(a)免费的,(b)支持软件使用的库,(c)使用GCC,因此它不受MSVC之间的辩证变化的影响和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. 然而,语言和可用库中的这些辩证变体(例如MSVC没有带来getopt的实现)意味着在MinGW和MSVC之间移植程序可能非常繁琐。 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. 我的经验 - 不可否认的是,因为我只做了几次这样做 - 在MinGW32和Linux之间移植应用程序比在MinGW和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. 显然,具有非可移植依赖性的应用程序(例如Win32特定的API使用)将需要为新平台重写相关组件,但是对于标准库,头文件和语言方言的差异,您将遇到的问题要少得多。

QT does a fairly good job of providing a platform abstraction layer. QT在提供平台抽象层方面做得相当不错。 It provides APIs for database access, threading, I/O and many other services as well as the GUI. 它提供了用于数据库访问,线程,I / O和许多其他服务以及GUI的API。 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. 在可能的情况下使用QT API应该有助于提高可移植性和MinGW附带的Unix / Linux风格的库意味着它可以为您提供一个很好的平台,使用Win32和Linux之间的应用程序以相对较少的平台相关代码进行移植。

EDIT: The qt development packages in Cygwin are: 编辑: Cygwin中的qt开发包是:

  • qt4: Qt application framework (source) qt4:Qt应用程序框架(源码)
  • qt4-devel-tools: Qt4 Assistant, Designer, and Linguist qt4-devel-tools:Qt4助理,设计师和语言学家
  • qt4-doc: Qt4 API documentation qt4-doc:Qt4 API文档
  • qt4-qtconfig: Qt4 desktop configuration app qt4-qtconfig:Qt4桌面配置应用
  • qt4-qtdemo: Qt4 demos and examples qt4-qtdemo:Qt4演示和示例

You'll probably also need gcc4-g++ and some other bits and pieces. 您可能还需要gcc4-g ++和其他一些零碎的东西。 This listing on the cygwin web site has a list of the packages. cygwin网站上的这个列表有一个包列表。

"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". 对于除了5之外的所有人都是“是”。你必须为Linux单独构建可执行文件,但这应该是直截了当的,因为4的答案是“是”。

Make sure you install all the development headers you need on both platforms. 确保在两个平台上安装所需的所有开发标头。

Yes, Yes, Yes, Yes (if you write it carefully and don't use anything specific to cygwin), No. 是,是,是,是(如果您仔细编写并且不使用特定于cygwin的任何内容),请注意。

On 5: it may be possible to cross-compile from Cygwin to Linux, I really don't know. 5:有可能从Cygwin交叉编译到Linux,我真的不知道。 If it is, then technically some executables "built by Cygwin" would run on Linux. 如果是,那么从技术上讲,“由Cygwin构建”的一些可执行文件将在Linux上运行。 But Cygwin executables won't run on Linux. 但Cygwin可执行文件不能在Linux上运行。

1-4: The answers to these are all "yes", because all of these features you are asking about are part of the POSIX standard. 1-4:这些答案都是“是”,因为您询问的所有这些功能都是POSIX标准的一部分。 Cygwin is basically a POSIX layer for Windows so, naturally, Cygwin includes all of these features. Cygwin基本上是Windows的POSIX层,因此,Cygwin自然而然地包含了所有这些功能。

5: No, Cygwin binaries will not execute under the Linux kernel, because ultimately the code generated by Cygwin is Windows native code. 5:不,Cygwin二进制文件不会在Linux内核下执行,因为最终Cygwin生成的代码是Windows本机代码。 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). 它将链接到通常的Windows DLL(如kernel32.dll),而Linux甚至没有DLL的概念(它具有相似但不同的共享对象)。 More importantly, executables built under Cygwin will be in the PE format, but Linux generally uses the ELF format for executables. 更重要的是,在Cygwin下构建的可执行文件将采用PE格式,但Linux通常将ELF格式用于可执行文件。 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. 当然,您可以在Cygwin下进行交叉编译,从而生成本机Linux可执行文件,但听起来并不像您正在寻找的那样。 Also, compiling a new version of GCC to use as a cross-compiler under Cygwin is probably no trivial task. 此外,编译一个新版本的GCC用作Cygwin下的交叉编译器可能不是一项简单的任务。

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. 6: Cygwin下的GCC不需要使用-lpthread因为Cygwin下的所有pthread代码都在cygwin1.dll中,默认情况下它总是被链接。

7: This is a bug in GCC (on all platforms). 7: 这是GCC中的一个错误 (在所有平台上)。 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. 8: ConcernedOfTunbridgeWells做了很好的解释,所以我没有什么可说的。 However, it's worth noting that Cygwin has the X.org X Window System in its package list. 但是,值得注意的是Cygwin在其包列表中有X.org X Window系统。 With Cygwin 1.7.x, setting it up and using it is a breeze and it seems pretty rock-solid. 使用Cygwin 1.7.x,设置和使用它是轻而易举的 ,它似乎非常坚如磐石。 If you want to use Qt with X, I'd recommend using Cygwin's X server. 如果你想将Qt与X一起使用,我建议使用Cygwin的X服务器。

In response to #7, the version of the C++ compiler that you have is probably out of date. 为响应#7,您拥有的C ++编译器版本可能已过时。 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/ 如果你不需要linux / posix可移植性,我会切换到非cygwin MinGW GCC编译器 - 你可以在http://tdragon.net/recentgcc/获得4.4.1

关于6,你不需要-lpthread,因为Pthreads支持是Cygwin DLL的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM