Hari Krishna
Hari Krishna

Reputation: 551

Compiling a C prog winth unix syle header files in windows

well i have a few Cpp source and header files, and the header files have include statements in the form,

#include<include/config.h>
#include<include/controls.h>

the thing is im using gcc on windows and it says no such file or directory as the windows style paths has '/' and not '\' ,

so i changed the path to include\config.h but again, the problem is config.h has many header files included in it with the similar unix path style, and its not feasible to change the paths in all the header files cos its a library and there are 100s of such headers, is there any way to compile this using GCC (minGW) ??

Thanks :)

this may sound like a silly problem, sorry if it is!!..

Upvotes: 0

Views: 1504

Answers (4)

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84189

Don't change forward slash / to back-slash \ - you are making the compiler to interpret the next character as a special character \c. GCC has no problem dealing with UNIX-style paths on Windows. The problem is probably the lack of -I directive to the compiler - something like -I. to search for files in current and sub-directories.

Upvotes: 0

Perry Horwich
Perry Horwich

Reputation: 2846

A good discussion of your issue can be seen here:

How to generate a OS independent path in c++

Upvotes: 0

user257111
user257111

Reputation:

I don't think the direction of the / is the problem here. Windows should convert between the two for you when calling its API precisely for the purposes of (some) unix compatibility.

I think the problem is the include path. Try compiling your program with

gcc -o output.exe -I"c:\path\to\directory\above\include" file.c

So that in the directory you specify with the include flag, there is a subdirectory "include" containing your headers. This assumes all your paths in your other headers are relative to this.

Upvotes: 2

wallyk
wallyk

Reputation: 57784

config.h and controls.h are not standard header files. Try this instead:

#include "include/config.h"
#include "include/controls.h"

Even better would be to use the command line to specify the include directory and use

#include "config.h"
#include "controls.h"

Probably mingw uses the same option as all other c compilers: (compiler name) -I(directory name)...

As others have stated, / vs. \ is a non-issue. Even Microsoft compilers and utilities accept / everywhere. The use of \ is a historical mistake, perpetrated needlessly.

Upvotes: 0

Related Questions