是否可以使用Cygwin或MinGW将Linux守护程序移植到Windows?

时间:2021-04-30 01:53:05

I have a Linux C++ application which run as a daemon. When user executes this application, it will be running in the background, listening on a port, and waiting for connection from the clients.

我有一个Linux C ++应用程序作为守护进程运行。当用户执行此应用程序时,它将在后台运行,侦听端口,并等待来自客户端的连接。

Is it possible to port this kind of application to Windows platform using Cygwin or MinGW?

是否可以使用Cygwin或MinGW将此类应用程序移植到Windows平台?

Thanks.

2 个解决方案

#1


2  

Cygwin aims at POSIX/Linux source level compatibility, so your application is supposed to build and work there with no or only minor modifications.

Cygwin的目标是POSIX / Linux源代码级兼容性,因此您的应用程序应该在没有修改或仅进行微小修改的情况下构建和工作。

MinGW does not try to provide such a compatibility layer. It's just the GNU toolchain for Windows, so you would need to replace any uses of POSIX/Linux-specific APIs with Windows equivalents.

MinGW不会尝试提供这样的兼容性层。它只是Windows的GNU工具链,因此您需要使用Windows等效替换POSIX / Linux特定API的任何使用。

#2


2  

It is possible to port almost anything (unless it makes sense only to one OS). The question is, "how hard is it to port application X"? And to help answer that question, we need to see source code.

几乎可以移植任何东西(除非只对一个操作系统有意义)。问题是,“移植应用程序X有多难”?为了帮助回答这个问题,我们需要查看源代码。

General purpose tips

It basically boils down to how much compiler/system-dependent code you've spread out over your code base. I see you're using at least two things that are sensitive: daemons and sockets.

它基本上归结为您在代码库中分布的编译器/系统相关代码的数量。我发现你至少使用了两件敏感的东西:守护进程和套接字。

Daemons are tricky to port as the equivalent on Windows (a windows service) requires different platform-specific code. This is fixed cost (e.g. does not vary on the size of the rest of the application).

守护进程很难移植,因为Windows(Windows服务)上的等效代码需要不同的平台特定代码。这是固定成本(例如,不会因应用程序其余部分的大小而变化)。

Sockets are more or less tricky to port depending on whether you're using advanced networking features (asynchronous I/O, etc.), which tend to vary more from system to system. It also depends on whether you abstracted socket manipulation code into some re-usable component. Windows supports a very similar sockets interface (the classic BSD socket interface with minor modifications to random parts of the API). Changing one Socket class is easier than changing your code if you didn't write a wrapper class.

套接字或多或少难以移植,具体取决于您是否使用高级网络功能(异步I / O等),这些功能往往因系统而异。它还取决于您是否将套接字操作代码抽象为一些可重用的组件。 Windows支持非常相似的套接字接口(经典的BSD套接字接口,对API的随机部分进行微小修改)。如果没有编写包装类,更改一个Socket类比更改代码更容易。

#1


2  

Cygwin aims at POSIX/Linux source level compatibility, so your application is supposed to build and work there with no or only minor modifications.

Cygwin的目标是POSIX / Linux源代码级兼容性,因此您的应用程序应该在没有修改或仅进行微小修改的情况下构建和工作。

MinGW does not try to provide such a compatibility layer. It's just the GNU toolchain for Windows, so you would need to replace any uses of POSIX/Linux-specific APIs with Windows equivalents.

MinGW不会尝试提供这样的兼容性层。它只是Windows的GNU工具链,因此您需要使用Windows等效替换POSIX / Linux特定API的任何使用。

#2


2  

It is possible to port almost anything (unless it makes sense only to one OS). The question is, "how hard is it to port application X"? And to help answer that question, we need to see source code.

几乎可以移植任何东西(除非只对一个操作系统有意义)。问题是,“移植应用程序X有多难”?为了帮助回答这个问题,我们需要查看源代码。

General purpose tips

It basically boils down to how much compiler/system-dependent code you've spread out over your code base. I see you're using at least two things that are sensitive: daemons and sockets.

它基本上归结为您在代码库中分布的编译器/系统相关代码的数量。我发现你至少使用了两件敏感的东西:守护进程和套接字。

Daemons are tricky to port as the equivalent on Windows (a windows service) requires different platform-specific code. This is fixed cost (e.g. does not vary on the size of the rest of the application).

守护进程很难移植,因为Windows(Windows服务)上的等效代码需要不同的平台特定代码。这是固定成本(例如,不会因应用程序其余部分的大小而变化)。

Sockets are more or less tricky to port depending on whether you're using advanced networking features (asynchronous I/O, etc.), which tend to vary more from system to system. It also depends on whether you abstracted socket manipulation code into some re-usable component. Windows supports a very similar sockets interface (the classic BSD socket interface with minor modifications to random parts of the API). Changing one Socket class is easier than changing your code if you didn't write a wrapper class.

套接字或多或少难以移植,具体取决于您是否使用高级网络功能(异步I / O等),这些功能往往因系统而异。它还取决于您是否将套接字操作代码抽象为一些可重用的组件。 Windows支持非常相似的套接字接口(经典的BSD套接字接口,对API的随机部分进行微小修改)。如果没有编写包装类,更改一个Socket类比更改代码更容易。