Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chdir not declared, compilation error g++

I am trying to compile a relatively simple application that I obtained from the web..

When running make I get the following error:

In file included from main.cpp:2:0:
os.h: In function ‘void myOpenDir(const char*)’:
os.h:13:16: error: ‘chdir’ was not declared in this scope

The file os.h looks like this:

#ifndef OS_H
#define OS_H


#if defined(__GNUG__)

#define INT64 long long
#define UINT64 unsigned long long
#include <dirent.h>
#define SPRTR '/'
void myOpenDir(const char* dirpath)
{
    chdir(dirpath);
}

#elif defined(_MSC_VER)
    #define INT64 __int64
    #define UINT64 unsigned __int64
    #include <direct.h>
    #define SPRTR '\\'
    void myOpenDir(const char* dirpath)
    {
        _chdir(dirpath);
    }
        #else
        #error "Platform not supported. Need to update source code"
        #endif 
#endif

Someone got an idea why it wont compile?

I also used a g++ compiler via g++-4.7.real -c main.cpp but so far no luck.

like image 356
Jasper Avatar asked Dec 21 '22 13:12

Jasper


1 Answers

Add #include <unistd.h>, as per the chdir manual.

like image 122
Sjoerd Avatar answered Jan 07 '23 00:01

Sjoerd