C: 在 Windows 中运行 Unix 配置文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2526878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C: Running Unix configure file in Windows
提问by
I would like to port a few applications that I use on Linux to Windows. In particular I have been working on wdiff. A program that compares the differences word by word of two files.
我想将我在 Linux 上使用的一些应用程序移植到 Windows。特别是我一直在研究wdiff。一个逐字比较两个文件差异的程序。
Currently I have been able to successfully compile the program on windows through Cygwin. However, I would like to run the program natively on Windows similar to the Project: UnixUtils.
目前我已经能够通过Cygwin在windows上成功编译程序。但是,我想在类似于 Project: UnixUtils 的Windows 上本地运行该程序。
How would I go about porting unix utilities on a windows environment?
我将如何在 Windows 环境中移植 unix 实用程序?
My possible guess it to manually create the ./configure file so that I can create a proper makefile. Am I on the right track? Has anyone had experience porting GNU software to windows?
我可能猜测它手动创建 ./configure 文件,以便我可以创建一个正确的 makefile。我在正确的轨道上吗?有没有人有将 GNU 软件移植到 Windows 的经验?
Update:
更新:
I've compiled it on Code::Blocks and I get two errors:
我已经在 Code::Blocks 上编译了它,但出现了两个错误:
wdiff.c|226|error: `SIGPIPE' undeclared (first use in this function)
readpipe.c:71: undefined reference to `_pipe'
readpipe.c:74: undefined reference to `_fork
wdiff.c|226|error: `SIGPIPE' 未声明(第一次在这个函数中使用)
readpipe.c:71: 对 `_pipe' 的未定义引用
readpipe.c:74: 对 `_fork 的未定义引用
This is a linux signal that is not supported by windows... equvilancy?
这是windows不支持的linux信号... equvilancy?
- wdiff.c|1198|error: `PRODUCT' undeclared (first use in this function)|
- wdiff.c|1198|错误:`PRODUCT'未声明(第一次在这个函数中使用)|
this is in the configure.in file... hardcode would probably be the fastest solution...
这是在 configure.in 文件中......硬编码可能是最快的解决方案......
Outcome:
结果:
MSYS took care of the configure problems, however MinGW couldnt solve the posix issues. I attempt to utilize pthreadsas recommended by mrjoltcola. However, after several hours I couldnt get it to compile nor link using the provided libraries. I think if this had worked it would have been the solution I was after. Special mention to Michael Madsen for MSYS.
MSYS 解决了配置问题,但是 MinGW 无法解决 posix 问题。我试图利用并行线程所推荐的mrjoltcola。但是,几个小时后,我无法使用提供的库进行编译或链接。我认为如果这有效,那将是我所追求的解决方案。特别提及 Michael Madsen 的 MSYS。
采纳答案by Dan Andreatta
You can have a look at MinGW (and MSYS), which are similar to cygwin, but gcc produce native Windows executables. However, since the Unix emulation is not as good as cygwin, you may have to adjust your code.
您可以查看 MinGW(和 MSYS),它们类似于 cygwin,但 gcc 生成本地 Windows 可执行文件。但是,由于 Unix 仿真不如 cygwin,您可能需要调整您的代码。
回答by codenheim
Yes. If you stick to the standard C library, and POSIX functions, most is available on Windows. You may just have to find the implementations. There are implementations of things that do not require Cywgin or MinGW (such as a pthreads package, etc.)
是的。如果您坚持使用标准 C 库和 POSIX 函数,则大多数都可以在 Windows 上使用。您可能只需要找到实现。有一些不需要 Cywgin 或 MinGW 的东西的实现(例如 pthreads 包等)
Also, there is a great book that is written in the style of W. Richard Steven's Advanced Proramming in the UNIX Environment, and the book is Windows System Programming, author Johnson Hart. He has a 4th edition. It focuses on System Programming, there is no GUI treatment whatsoever.
此外,还有一本以 W. Richard Steven 的Advanced Proramming in the UNIX Environment风格编写的好书,这本书是Windows System Programming,作者 Johnson Hart。他有第 4 版。它专注于系统编程,没有任何 GUI 处理。
http://www.amazon.com/Windows-Programming-Addison-Wesley-Microsoft-Technology/dp/0321657748
http://www.amazon.com/Windows-Programming-Addison-Wesley-Microsoft-Technology/dp/0321657748
It is the best book I know of for a UNIX programming moving to Windows.
这是我所知道的关于迁移到 Windows 的 UNIX 编程的最好的书。
回答by Dan Andreatta
Always try to following standarts even when porting applications. POSIX compliant compilers exist on windows/Linux. You can try mingw. It has full toolchain required to build standart POSIX application (GNU Linux as well). Check out Dev-Cpp it eases the work.
即使在移植应用程序时也始终尝试遵循标准。Windows/Linux 上存在符合 POSIX 的编译器。你可以试试 mingw。它具有构建标准 POSIX 应用程序(也包括 GNU Linux)所需的完整工具链。查看 Dev-Cpp 它可以简化工作。
回答by Andrew O'Reilly
MinGWis about the easiest way to get gcc and associated binary utilities (including gdb) on a Windows PC. It includes header files and import libraries so that you can call native Windows APIs. If you want more of an integrated IDE development environment you could download Microsoft's free Visual Studio Express C++.
MinGW是在 Windows PC 上获取 gcc 和相关二进制实用程序(包括 gdb)的最简单方法。它包括头文件和导入库,以便您可以调用本机 Windows API。如果您想要更多的集成 IDE 开发环境,您可以下载 Microsoft 的免费Visual Studio Express C++。
Either way you'll likely have to convert some of the function calls to use Windows specific APIs (if you want a book I'd also recommend the Hart book mentioned in mrjoltcola's answer). For simple command line tools this conversion is usually not a huge deal, the big porting nightmares tend to involve tools with GUIs which have deep embedded dependencies on the GUI framework provided by the OS.
无论哪种方式,您都可能必须将某些函数调用转换为使用特定于 Windows 的 API(如果您想要一本书,我还推荐 mrjoltcola 的回答中提到的 Hart 书)。对于简单的命令行工具,这种转换通常不是什么大问题,大的移植噩梦往往涉及带有 GUI 的工具,这些 GUI 对操作系统提供的 GUI 框架具有深入的嵌入式依赖关系。