I am trying to compile a linux written program under windows (I use mingw)
void make_directory(const char* name) {
mkdir(name1, name2);
}
There is an error:
Too Many Arguments to function 'int mkdir(const char*)'
Any idea to solve this?
I managed to get away with this, for a Linux written program building under mingw-w64:
#if (defined(_WIN32) || defined(__WIN32__))
#define mkdir(A, B) mkdir(A)
#endif
As said in the comments, mkdir()
takes only one argument. However since this function is deprecated you should use _mkdir()
instead:
int _mkdir(const char *dirname);
int _wmkdir(const wchar_t *dirname); /* for wide-character */
If you want your function on both systems (linux / mingw):
void make_directory(const char* name)
{
#ifdef __linux__
mkdir(name, 777); /* Or what parameter you need here ... */
#else
_mkdir(name);
#endif
}
Edit:
MinGW implementation:
_mkdir():
_CRTIMP int __cdecl __MINGW_NOTHROW _mkdir (const char*);
mkdir():
_CRTIMP int __cdecl __MINGW_NOTHROW mkdir (const char*);
Both are specified in io.h
, but i guess its better to include direct.h
instead (includes io.h
in its part).
I'll assume that name1
and name2
are both names of directories you want to create (but see below).
mkdir()
creates (or attempts to create) a single directory. If you want to create two directories, you need to call mkdir()
twice.
And just to add to the confusion, the POSIX mkdir()
function actually takes two arguments -- but the second argument is not a name. Quoting the man page on my system:
#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname, mode_t mode);
The _mkdir()
function mentioned in ollo's answer is specific to Microsoft Windows, and it takes a single argument; modes, i.e. permissions, work differently on Windows than they do on POSIX (Unix, Linux, et al) systems.
But your compiler obviously thinks that mkdir()
takes only one argument, which makes wonder why it thinks so. What header did you #include
to get the declaration of the mkdir
function?
As I mentioned above, the POSIX mkdir()
takes two arguments, but the second is a mode_t
, not a name. You say the code was originally written for Linux. Are the arguments really called name1
and name2
, or did you try to simplify the code by changing the names? Can you update the question to show us the actual copy-and-pasted code?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With