Thread: Another pitiful request for help

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    16

    Another pitiful request for help

    Please excuse me,

    I'm a proficient C programmer in a GNU/Linux environment who is attempting to learn to program on Windows. I decided I would use MinGW and MSYS to mimic the environment I was already used to (I'm not inclined to get to used to VC++ if you get my drift).

    So, after reading the lovely documentation, I seem to have everything installed correctly and even got my hello world program running. Huzzah.

    Well, suddenly an error came up when trying to port one of my old programs. I have a function which does this:
    Code:
    int isDir(char *candidate)
    {
    	DIR * dir = opendir(candidate);
    
    	if (dir == NULL)
    	{
    		return 0;
    	} else
    	{
    		return 1;
    	}
    }
    Yes, I'm sure there is a better way to check to see if something is a directory, but let's focus on the error

    I compile like so: gcc donner4.c -o donner4 -lpthreads (pthreads is working)

    I get this:

    In file included from donner4.c:16:
    C:/msys/1.0/mingw/include/sys/dirent.h:62: parse error before "__ino64_t"
    C:/msys/1.0/mingw/include/sys/dirent.h:66: parse error before '}' token
    C:/msys/1.0/mingw/include/sys/dirent.h:69: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:70: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:71: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:72: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:73: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:75: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:79: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:80: parse error before '*' token
    donner4.c: In function `isDir':
    donner4.c:54: `dir' undeclared (first use in this function)
    donner4.c:54: (Each undeclared identifier is reported only once
    donner4.c:54: for each function it appears in.)

    So we at least know dirent.h is being included.

    Again, I'm not experienced enough with MinGW or Windows programming in general to know what the matter is, only that Google has a bunch of dirent.h problems online (of course, my ignorance renders me incapable of comprehending them).

    Would a kind soul be willing to help me? I would most appreciate it.

    Thanks!

    rokenrol

    EDIT (a few minutes later):
    You should also know that this is a completely new install of what I believe is the latest version of everything involved, so if versions matter that might help you.

    Also, the program works perfectly fine back on Slackware. But in Windowsland it fails. Anyone surprised?

    Again, grazie!
    Last edited by rokenrol; 10-12-2006 at 07:56 PM.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Oh dear, OH DEAR!!!
    You are using Linux headers on WINDOWS!

    Why so much mess? Just download Dev-C++ and you won't have those problems.
    Last edited by maxorator; 10-13-2006 at 02:31 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    16
    Well, the other headers in the MinGW include folder work, and since MinGW is a Windows port of gcc, I'm going to go ahead and assume that it's components are for use in Windows. Especially since it's "Minimalist GCC for Windows" and its purpose is to create a Unix-like environment so that one can use Unix tools to build programs.

    Ahem.

    I'm just having issues with this specific one. stdio et al work fine so I don't know that it's necessarily the linux headers.

    Also, I've used Dev-C++, and I just can't get the hang of any IDE, let alone one so replete with powers as that one. If anyone has an idea why some headers work and others don't, please drop me a line.

    I would like to emphasize that Dev-C++ is a wonderful tool, though, and maybe someday when I have the attention span I'll learn to use it and make it part of my system. But, come on, I'm young, I'm supposed to do wild, daring things
    Last edited by rokenrol; 10-13-2006 at 08:01 PM.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Those are some odd errors. I've used dirent.h many times, never had an issue. When you include dirent.h, do you include any other headers (donner4.h?) before it? Do these headers contain a blank newline at the end? Does gcc say anything more useful if you start turing warnings on? (Compile with -Wall -W )
    Code:
    int isDir(char *candidate)
    {
    	DIR * dir = opendir(candidate);
    
    	if (dir == NULL)
    	{
    		return 0;
    	} else
    	{
    		return 1;
    	}
    }
    Gah. closedir that directory handle when you're done with it. (Also - you could stat() the directory... dunno which is better though.)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    16
    Perhaps it is unprofessional of me, but being as it is an old project of mine, I don't actually have a donner4.h file simply because the entire program was more an exercise in socket programming than something I'd actually use. If you like, I can post the extent of the code (which does compile in Linux). It appears to be some MinGW issue.

    Here is my complete include section:

    #ifdef _WIN32
    #include <winsock2.h>
    #else

    #include <netdb.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #endif
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <string.h>
    #include <syslog.h>
    #include <sys/dirent.h>

    That is exactly like I have it on Linux, and it works fine there.

    Here is the output when I compile like you suggested, with warnings:

    $ gcc donner4.c -o donner4 -lpthread -Wall -W
    In file included from donner4.c:11:
    C:/msys/1.0/mingw/include/pthread.h:307: redefinition of `struct timespec'
    In file included from donner4.c:16:
    C:/msys/1.0/mingw/include/sys/dirent.h:62: parse error before "__ino64_t"
    C:/msys/1.0/mingw/include/sys/dirent.h:66: parse error before '}' token
    C:/msys/1.0/mingw/include/sys/dirent.h:69: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:70: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:71: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:72: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:73: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:75: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:79: parse error before '*' token
    C:/msys/1.0/mingw/include/sys/dirent.h:80: parse error before '*' token
    donner4.c: In function `isDir':
    donner4.c:56: `dir' undeclared (first use in this function)
    donner4.c:56: (Each undeclared identifier is reported only once
    donner4.c:56: for each function it appears in.)
    donner4.c: In function `processGet':
    donner4.c:121: warning: passing arg 1 of `open' from incompatible pointer type
    donner4.c:70: warning: unused variable `j'
    donner4.c:93: warning: unused variable `error'
    donner4.c: In function `processRequest':
    donner4.c:162: warning: initialization makes integer from pointer without a cast
    donner4.c: In function `main':
    donner4.c:236: warning: passing arg 4 of `pthread_create' makes pointer from integer without a cast
    donner4.c:231: warning: statement with no effect
    donner4.c:184: warning: unused parameter `argc'

    The warnings at the end were also given on Linux, but the program works fine with them (again, just a simple project). The pthread.h error only shows when I compile with warnings, and then the errors below that (but above the "standard" warnings) are completely unique to Windows. It is MinGW 3.1.0 and the latest version of the pthread library for Windows. Again, the packages seem to be recognized correctly as at least I am getting cogent error messages, so it seems to be an implementation issue.

    If you are interested in helping me solve this debacle, just ask for whatever info you need. Again, Windows is a strange bedfellow for me, so I'm prone to making a stupid mistake.

    Thanks so much!

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    This compiles fine in my msys
    Code:
    #include<stdio.h>
    #include<dirent.h>
    
    int main(void)
    {
        DIR *d = opendir(".");
        struct dirent *p = readdir(d);
        printf("First file=%s\n",p->d_name);
        closedir(d);
        return 0;
    }
    sys/dirent.h results in prog.c:2:23: sys/dirent.h: No such file or directory for me
    It seems to me that perhaps your include paths are a bit too keen, and you're picking up someone elses header files.

    Code:
    $ gcc -M prog.c
    prog.o: prog.c \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/stdio.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/_mingw.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/include/stddef.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/include/stdarg.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/sys/types.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/dirent.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/io.h \
      c:/mingw/bin/../lib/gcc/mingw32/3.4.2/../../../../include/stdint.h
    The -M option outputs dependencies, and from that you should be able to see where you get all the header files from.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    rokenrol, I guess you saw you have sys/dirent.h missing and then you just ripped off some wrong one from internet.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    16
    Maxorator --
    I just re-read my response post to you...I have a very brusque sense of humor, and I sort of forget I'm not friends with everybody yet, so I let it slip. I was rude, I'm sorry, I meant it as a joke, and, incidentally, you're right It DID come with a dirent.h, but if I recall I think I fubarred something and found a quick replacement.

    Salem:
    Good one! I always forget the compiler does more than just compile (I heart simplicity).

    Thanks all of you for being so kind and helpful.

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by rokenrol
    Maxorator --
    I just re-read my response post to you...I have a very brusque sense of humor, and I sort of forget I'm not friends with everybody yet, so I let it slip. I was rude, I'm sorry, I meant it as a joke, and, incidentally, you're right It DID come with a dirent.h, but if I recall I think I fubarred something and found a quick replacement.

    Salem:
    Good one! I always forget the compiler does more than just compile (I heart simplicity).

    Thanks all of you for being so kind and helpful.
    I read through the replies and couldn't find anything rude.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    16
    Incidentally, does anyone have a good resource for getting dirent? As far as I can tell, I should use this one I found on the GIMP for Windows download page...says it's dirent for Windows, but I want to hold off until someone with experience tells me what to do so I can be sure that I did things correctly. Thanks!

  11. #11
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    You should have dirent.h, it just isn't in the sys folder.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  12. #12
    Registered User
    Join Date
    Feb 2006
    Posts
    16
    I think perhaps my best solution should be to completely reinstall my MinGW/MSYS setup. I was lazy and took a MinGW setup created by my one experiment with Dev-C++ and stuck it in MSYS's "mingw" folder. Unfortunately, several iffy devpaks and some misled tinkering rendered it slightly broken. My best bet is to just go to the mingw.org download page and get it all over again.

    May this thread serve as a lesson to all you lazy programmers out there: reform!

  13. #13
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by rokenrol
    Perhaps it is unprofessional of me, but being as it is an old project of mine, I don't actually have a donner4.h
    I was merely using donner.h as an example - nothing wrong with not having it.

    Also, if for some reason you don't have a header like dirent that should be in the MinGW installation, you can always find the files in the downloads at Mingw's site. (If it's a standard or system header) I originally started with a Dev-C++ install of MinGW, but now I do my own straight from Mingw's site.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  14. #14
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by rokenrol
    I think perhaps my best solution should be to completely reinstall my MinGW/MSYS setup. I was lazy and took a MinGW setup created by my one experiment with Dev-C++ and stuck it in MSYS's "mingw" folder. Unfortunately, several iffy devpaks and some misled tinkering rendered it slightly broken. My best bet is to just go to the mingw.org download page and get it all over again.

    May this thread serve as a lesson to all you lazy programmers out there: reform!
    Dev-C++ comes with everything you need. Just reinstall Dev-C++ and you should have all necessary header files. Still, dirent.h is NOT in sys folder.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with client GET request path
    By NuNn in forum C Programming
    Replies: 1
    Last Post: 02-25-2009, 03:34 PM
  2. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  3. my HTTP request handler code correct?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 04-25-2008, 04:01 AM
  4. denied request
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 09-20-2001, 11:35 PM