4

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.

Jasper
  • 628
  • 1
  • 9
  • 19

1 Answers1

11

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

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • 1
    Brilliant thanks! I'll see if this also works in the other applications. In 8 minutes Ill give you 2 thumbs up and check your answer. – Jasper Nov 12 '12 at 08:22
  • Indeed, BCI2000 has the same issue with the same solution, not documented in their wiki: http://www.bci2000.org/wiki/index.php/Programming_Howto:Quickstart_Guide#Prerequisites_.28Linux.29 Great answer. – bright-star Apr 29 '14 at 23:42
  • I've played with conditional loads ` #ifdef _WIN32 #include #define chdir _chdir #else #include #endif` but finally i've been forced to add both of them and worked. I never spected the mingw to create really cross-platform binarys. – m3nda Oct 19 '15 at 02:09