在windows中编译C prog winth unix syle头文件

发布于 2024-11-01 08:06:50 字数 400 浏览 2 评论 0原文

好吧,我有一些 Cpp 源文件和头文件,并且头文件在表单中包含包含语句,

#include<include/config.h>
#include<include/controls.h>

问题是我在 Windows 上使用 gcc,它说没有这样的文件或目录,因为 Windows 样式路径有“/”而不是“ \' ,

所以我将路径更改为 include\config.h 但同样,问题是 config.h 中包含许多具有类似 unix 路径样式的头文件,并且更改所有头文件中的路径是不可行的因为它是一个库,并且有 100 个这样的标头,有没有办法使用 GCC (minGW) 来编译它?

谢谢:)

这可能听起来像一个愚蠢的问题,如果是的话,抱歉!..

well i have a few Cpp source and header files, and the header files have include statements in the form,

#include<include/config.h>
#include<include/controls.h>

the thing is im using gcc on windows and it says no such file or directory as the windows style paths has '/' and not '\' ,

so i changed the path to include\config.h but again, the problem is config.h has many header files included in it with the similar unix path style, and its not feasible to change the paths in all the header files cos its a library and there are 100s of such headers, is there any way to compile this using GCC (minGW) ??

Thanks :)

this may sound like a silly problem, sorry if it is!!..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若无相欠,怎会相见 2024-11-08 08:06:51

不要将正斜杠 / 更改为反斜杠 \ - 您将使编译器将下一个字符解释为特殊字符 \c 。 GCC 在处理 Windows 上的 UNIX 样式路径时没有问题。问题可能是编译器缺少 -I 指令 - 例如 -I. 来搜索当前目录和子目录中的文件。

Don't change forward slash / to back-slash \ - you are making the compiler to interpret the next character as a special character \c. GCC has no problem dealing with UNIX-style paths on Windows. The problem is probably the lack of -I directive to the compiler - something like -I. to search for files in current and sub-directories.

擦肩而过的背影 2024-11-08 08:06:50

我不认为 / 的方向是这里的问题。当为了(某些)unix 兼容性而调用其 API 时,Windows 应该为您在两者之间进行转换。

我认为问题在于包含路径。尝试使用编译您的程序,

gcc -o output.exe -I"c:\path\to\directory\above\include" file.c

以便在您使用 include 标志指定的目录中,有一个包含标头的子目录“include”。这假设其他标头中的所有路径都与此相关。

I don't think the direction of the / is the problem here. Windows should convert between the two for you when calling its API precisely for the purposes of (some) unix compatibility.

I think the problem is the include path. Try compiling your program with

gcc -o output.exe -I"c:\path\to\directory\above\include" file.c

So that in the directory you specify with the include flag, there is a subdirectory "include" containing your headers. This assumes all your paths in your other headers are relative to this.

混吃等死 2024-11-08 08:06:50

config.hcontrols.h 不是标准头文件。试试这个:

#include "include/config.h"
#include "include/controls.h"

更好的是使用命令行指定包含目录并使用

#include "config.h"
#include "controls.h"

mingw 可能使用与所有其他 c 编译器相同的选项:(编译器名称) -I(目录name)...

正如其他人所说, /\ 不是问题。甚至 Microsoft 编译器和实用程序也到处接受 /\ 的使用是一个历史错误,是不必要的。

config.h and controls.h are not standard header files. Try this instead:

#include "include/config.h"
#include "include/controls.h"

Even better would be to use the command line to specify the include directory and use

#include "config.h"
#include "controls.h"

Probably mingw uses the same option as all other c compilers: (compiler name) -I(directory name)...

As others have stated, / vs. \ is a non-issue. Even Microsoft compilers and utilities accept / everywhere. The use of \ is a historical mistake, perpetrated needlessly.

2024-11-08 08:06:50

关于您的问题的很好的讨论可以在这里看到:

如何在 c++ 中生成独立于操作系统的路径

A good discussion of your issue can be seen here:

How to generate a OS independent path in c++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文