Menu

Reading a c: directory with C++

2002-09-16
2012-09-26
  • Nobody/Anonymous

    Hi Guys.

    I am having a slight problem with this piece of code:

    #include <iostream>
    #include <stdlib.h>
    #include <fstream>
    #include <sys/types.h>
    #include <stddef.h>
    #include <dirent.h>
    #include <stdio.h>
    using namespace std;

    int main(void) {
         DIR *directory;
         struct dirent *entries;
        
         directory=opendir("./");
         printf("Directory Contents:\n\n");
         while((entries=readdir(directory)))
        puts(entries->d_name);
         closedir(directory);
         return 0;
    }

    When i Compile I get a linker error like:

    "C:\TEMP\ccbwtgb.o    [Warning]In function main
                    [Linker error] undefined reference to
    `opendir
                    [Linker error] undefined reference to
    `readdir
                    [Linker error] undefined reference to
    `closedir

    any idea's?

    BR Kurt

     
    • Jack Black

      Jack Black - 2002-09-16

      I cut'n'paste the code and it compiled fine. I am using the latest MinGW 3.2.

      Have you got your library paths set up correctly?

      BlakJak :]

       
    • Nobody/Anonymous

      Hi BlakJak.

      I think that I have my library path set-up correctly since this is the only program where I have experienced this problem, but can you give me a hint on what to check regarding this set-up? I am running DEV-C++ 4.9.5.0. I don&#8217;t know about the exact version of my MinGW 3.2. compiler - which version should it be and where can I see the version number.

      BR Kurt.

       
    • Nobody/Anonymous

      Hi BlakJak.

      Please tell me which version you have and where to check the exact version on the MinGW compiler. (I am running DEV-C++ 4.9.5.0).

      Could you also please tell me how to check the set-up libary path? I think mine is OK.

       
      • Nobody/Anonymous

        To check your version go to a DOS prompt and type g++ --version   (note the double '-')

        Your library paths are under
        Tools->CompilerOptions->Directories->xxxx

        My xxxx's are setup as:

        Binaries: C:\SDK\DEV-CPP\Bin
                      C:\sdk\Dev-Cpp\lib\gcc-lib\mingw32\3.2

        Libraries:  c:\sdk\dev-cpp\lib

        C includes:  C:\SDK\DEV-CPP\include

        C++ Includes:  C:\sdk\Dev-Cpp\include\c++\3.2
                               C:\SDK\DEV-CPP\include

        Note that I am running version 3.2 of gcc. Your lib paths and include paths which are specific to the version will be different if you are not running 3.2

        BlakJak :]

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.