views:

91

answers:

2

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?

+1  A: 

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.

Carl Norum
It's already like this, in both files I've included `limits.h`
Nathan Campos
And `limits.h` actually defines `PATH_MAX`?
Carl Norum
+3  A: 

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.

Jonathan Leffler