getopt.h:在 Windows 中编译 Linux C 代码 [英] getopt.h: Compiling Linux C-Code in Windows

查看:28
本文介绍了getopt.h:在 Windows 中编译 Linux C 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Windows 下编译一组九个 *.c 文件(和九个相关的 *.h 文件).

I am trying to get a set of nine *.c files (and nine related *.h files) to compile under Windows.

该代码最初在 Linux 中设计为使用标准 GNU-Linux/C 库getopt.h"获取命令行参数.并且该库不适用于在 Windows 中构建 C 代码.

The code was originally designed in Linux to take command line arguments using the standard GNU-Linux/C library "getopt.h". And that library does not apply to building the C-code in Windows.

我想忽略我的代码现在所做的事情并提出以下问题.对于那些熟悉这个 C 库getopt.h"的人:如果我的代码依赖于 POSIX 风格的命令行参数,是否可以在 Windows 中构建和运行我的代码?或者我是否必须重新编写代码才能在 Windows 上工作,以不同的方式传递输入文件(并放弃getopt.h"依赖项)?

I want to ignore what my code does right now and ask the following question. For those of you familiar with this C-library "getopt.h": will it be possible to build and run my code in Windows if it depends on POSIX-style command-line arguments? Or will I have to re-write the code to work for Windows, passing input files differently (and ditching the "getopt.h" dependency)?

推荐答案

你说得对.getopt() 是 POSIX,而不是 Windows,您通常必须重新编写所有命令行参数解析代码.

You are correct. getopt() is POSIX, not Windows, you would generally have to re-write all command-line argument parsing code.

幸运的是,有一个项目,Xgetopt,适用于 Windows/MFC 类.

Fortunately, there is a project, Xgetopt, that is meant for Windows/MFC classes.

http://www.codeproject.com/Articles/1940/XGetopt-A-Unix-compatible-getopt-for-MFC-and-Win32

如果你可以在你的项目中使用它,它应该可以为你节省大量的编码,并防止你不得不返工所有的解析.

If you can get this working in your project, it should save you a fair bit of coding and prevent you from having to rework all parsing.

此外,它还带有一个很好的支持 GUI 的演示应用程序,您应该会觉得它很有帮助.

Additionally, it comes with a nice GUI-enabled demo app that you should find helpful.

祝你好运!

这篇关于getopt.h:在 Windows 中编译 Linux C 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆