Any Ideas

This is a discussion on Any Ideas within the C++ Programming forums, part of the General Programming Boards category; I am having a problem running across a method of opening, reading filenames, and closing a directory in order to ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Unhappy Any Ideas

    I am having a problem running across a method of opening, reading filenames, and closing a directory in order to pull filenames with a certain extension from. In searching, the only reference I found to accomplish such a task was on the delorie/djgpp website. I am using Dev-C++ version 4.9.7.6. On the web site, they posted an example program to explain how it was used. Just for my sake, I tried the program and got some errors. Following is the program code and the errors. I am not asking for anybody to write my code, just for some knowledge in determining where the problem is.



    Code:
    ---------------------------------------------------------------------------
    /*****************CODE**************************/
    #include <sys/types.h>
    #include <dirent.h>		/* Directory information.*/
    
    main()
    {
      DIR * dir_p;
      struct dirent * dir_entry_p;
       
    			/* Open the current directory*/	
      dir_p = opendir(".");
    
    			/* read each entry until NULL.*/
    
      while( NULL != (dir_entry_p = readdir(dir_p)))
      {
    		/* print the name of the file held in 
    		 * this directory entry.*/
    
        printf(" %s \n", dir_entry_p->d_name);
      }
    
    				/* Tidy up.*/
      closedir(dir_p);
    }
    --------------------------------------------------------------------------------
    ****************ERRORS****************************

    [Linker error] undefined reference to `opendir'
    [Linker error] undefined reference to `readdir'
    [Linker error] undefined reference to `closedir'
    **************************************************
    *

    The code is exactly how it was downloaded as a file. I am just doing some testing in order to determine how to implement in to my own program. Any help would be greatly appreciated.

    Thankfully,
    Kendal


    For some reason on my system it does not work.
    Like I said I get the following errors:

    [Linker error] undefined reference to `opendir'
    [Linker error] undefined reference to `readdir'
    [Linker error] undefined reference to `closedir'

    I am using Dev-C++, the latest version 4.9.7.6 and checked the dirent.h header file and it does make reference to opendir, readdir, and closedir. Any ideas why I get such a linker error??? Would you like to see my dirent.h header file???
    Last edited by gvector1; 02-18-2003 at 01:45 PM.

  2. #2
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    use code tags
    nextus, the samurai warrior

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    and don't double post, especially when your other thread is right below this one.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Unhappy Sorry

    Sorry!!!

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by alpha
    and don't double post, especially when your other thread is right below this one.
    Ooooh, Dumb

    Tried reinstalling?

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    code works fine with mingw 3.2, which should be the compiler you are working with, unless you changed it.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    184

    Thumbs up Reply

    The MingW32 compiler is the one I was working with, I deleted all of the Dev files and reinstalled and that seemed to fix that problem. I appreciate all the help, but now I have another problem. My coworker is using Dev-C++, same version and all. I try to compile a different program, a program I pulled from the forum to try and debug, and get a load of errors that don't make sense. When we compile the same program on my coworkers machine, it compiles. We checked the .ini file, and all of the setting and they are practically the same. Here are a few of the error messages I am getting:

    44 C:\Dev-Cpp\include\c++\ios || In file included from C:/Dev-Cpp/include/c++/ios
    44 C:\Dev-Cpp\include\c++\istream || from C:/Dev-Cpp/include/c++/istream
    28 C:\Dev-Cpp\include\c++\iosfwd:44 || bits/c++config.h: No such file or directory.
    24 C:\Dev-Cpp\include\c++\bits\fpos.h:44 || bits/c++io.h: No such file or directory.


    These errors don't make any sense to me because these files do exist and the lines seem valid.

    Extremely Grateful,
    Kendal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ideas, how do you get them? xD
    By Akkernight in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 01-22-2009, 02:53 AM
  2. cool ideas for a game
    By Shadow12345 in forum Game Programming
    Replies: 7
    Last Post: 05-18-2004, 08:37 PM
  3. idea's idea's idea's
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-29-2002, 12:30 AM
  4. Small app ideas
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 02-15-2002, 07:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21