分离要组织的代码

发布于 2024-08-09 20:16:07 字数 1174 浏览 6 评论 0 原文

我正在构建一个拉链应用程序,但它有一个声明,我想将其分离到另一个文件(compress-file.m)中,但只有当我分离文件时,我在使用变量进行编译时才会出现错误,请参阅:

[ubuntu@eeepc:~/Desktop] make
This is gnustep-make 2.0.2. Type 'make print-gnustep-make-help' for help.
Making all for app LeafZip...
 Creating LeafZip.app/....
 Compiling file main.m ...
main.m: In function ‘main’:
main.m:7: error: ‘PATH_MAX’ undeclared (first use in this function)
main.m:7: error: (Each undeclared identifier is reported only once
main.m:7: error: for each function it appears in.)
main.m:12: warning: implicit declaration of function ‘compressFile’
main.m:7: warning: unused variable ‘outFileName’
make[1]: *** [obj/main.o] Error 1
make: *** [LeafZip.all.app.variables] Error 2

另请参阅 main.m 文件的第 7 行:

char outFileName[PATH_MAX] = { 0 };

并查看 compress-file.m 的一些行:

#include <stdio.h>
#include <zlib.h>
#include <limits.h>

/* Buffer to hold data read */
char buf[BUFSIZ] = { 0 };
size_t bytes_read = 0;
gzFile *out = gzopen(outFileName, "wb");

我知道这是 Objective-C 扩展,但这只是因为当我解决这个问题时,我需要继续在 Objective-C 中进行开发 - C. 我需要做什么来纠正这个问题?

I'm building a zipper application, but it has a declaration that I want to separate it in another file (compress-file.m), but only when I separate the files I got an error when compiling with a variable, see it:

[ubuntu@eeepc:~/Desktop] make
This is gnustep-make 2.0.2. Type 'make print-gnustep-make-help' for help.
Making all for app LeafZip...
 Creating LeafZip.app/....
 Compiling file main.m ...
main.m: In function ‘main’:
main.m:7: error: ‘PATH_MAX’ undeclared (first use in this function)
main.m:7: error: (Each undeclared identifier is reported only once
main.m:7: error: for each function it appears in.)
main.m:12: warning: implicit declaration of function ‘compressFile’
main.m:7: warning: unused variable ‘outFileName’
make[1]: *** [obj/main.o] Error 1
make: *** [LeafZip.all.app.variables] Error 2

Also see the line 7 of main.m file:

char outFileName[PATH_MAX] = { 0 };

And see some lines of compress-file.m:

#include <stdio.h>
#include <zlib.h>
#include <limits.h>

/* Buffer to hold data read */
char buf[BUFSIZ] = { 0 };
size_t bytes_read = 0;
gzFile *out = gzopen(outFileName, "wb");

I know that is Objective-C extension, but it's only because when I solve this problem I will need to continue the development in Objective-C. What I need to do to correct this?

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

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

发布评论

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

评论(2

写给空气的情书 2024-08-16 20:16:07

PATH_MAX 并不总是通过包含 来定义。如果您想使用它,您可能需要依靠该片段:

#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX   /* Or possibly _XOPEN_PATH_MAX */
#endif /* PATH_MAX */

您是否在主程序中包含了 limits.h ?如果没有,您需要这样做。

PATH_MAX is not always defined by including <limits.h>. If you want to use it, you probably need to fall back on the fragment:

#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX _POSIX_PATH_MAX   /* Or possibly _XOPEN_PATH_MAX */
#endif /* PATH_MAX */

Did you even include limits.h in your main program? If not, you need to do so.

凡尘雨 2024-08-16 20:16:07

看起来 main.m 需要 #include 。似乎还需要包含一个描述 compressFile 的标头(我猜您已将其移至 compress-file.m 中)。

Looks like main.m needs to #include <limits.h>. It also seems like it will need to include a header describing compressFile (which I guess you moved into compress-file.m.

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