News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Moving to GCC question

Started by troels, January 18, 2006, 01:08:16 PM

Previous topic - Next topic

troels

Hi all,
I'm moving a MSVC6 project (an entire workspace really) to C::B. Import went well.

1. GCC and relative #include paths:

This compiles: #include "../include/someheader.h"
This doesn't compile: #include "../../include/someotherheader.h" ("No such file or directory")

Apparantly (this version of) GCC cannot handle two updirs ("../..").
Any way around this limitation?

Regards
Troels

Using 1.0rc2 with MinGW compiler, updated with Nightly Build Jan. 16
Running on Win2000 SP4, WinXP SP2

mandrav

GCC has no problems with two updirs (or three or four or whatever).
Just realize that it needs to find the included file...
Be patient!
This bug will be fixed soon...

thomas

More likely, your include paths are set up incorrectly. gcc (or MinGW for that matter) normally handles many levels of ../../../ without any problems.

Check that whatever it is you try to include really exists where the compiler would expect it (i.e. from one of the paths supplied as include paths).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

troels

Quote from: thomas on January 18, 2006, 01:17:16 PM
Check that whatever it is you try to include really exists...

It certainly does. It compiles in MSVC.

Quote from: mandrav on January 18, 2006, 01:15:38 PM
GCC has no problems with two updirs (or three or four or whatever).

Good to hear, quite a relief.

This might be a C::B issue then:

- If I right click the offending .c file and choose "Build file" in the menu it compiles!
- If I press Ctrl+F9 it doesn't compile ("No such file or directory")

Here's a little test C::B project for demonstrating this:
http://www.trak.dk/gcctest.zip
Also included in the zip is the corresponding MSVC project.
It compiles in MSVC, not in C::B (using Ctrl+F9)

Thanks
Troels

Michael

After adding the include directories, I had to modify the #include (mylib\src\mylib.c) in:


#include "mylib.h"


Then it compiled.

Quote
-------------- Build: Win32 Debug in gcctest ---------------
Compiling: .\mylib\src\mylib.c
Linking console executable: C:\test\gcctest\Debug\gcctest.exe
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings

Michael
[url="http://img207.imageshack.us/img207/9728/411948picture4em.png"]http://img207.imageshack.us/img207/9728/411948picture4em.png[/url]

thomas

Quote from: troels on January 18, 2006, 01:43:03 PMIt certainly does. It compiles in MSVC.
It is not as certain as you think.

In the project which you supplied, for example, none of the headers exist from the point of the compiler's view, there are no include directory settings at all, and the include files are in a subfolder.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

troels

#6
Quote from: Michael on January 18, 2006, 02:14:07 PM
After adding the include directories, I had to modify...

Sorry, buy this (gcctest.zip) is a perfectly valid project as is, I believe.
The idea is to not change anything. Especially not the source files.

Quote from: thomas on January 18, 2006, 02:21:17 PM
In the project which you supplied...there are no include directory settings at all

This is on purpose.

But, perhaps moving to gcc just requires adding include directories (adding gazillions of include directories if you have gazillions of subprojects) ??

Thanks
Troels

thomas

Quote from: troels on January 18, 2006, 02:26:15 PM
This is on purpose.

But, perhaps moving to gcc just requires adding include directories (adding gazillions of include directories if you have gazillions of subprojects) ??
Well, on purpose or not, it's wrong ;)

I don't know whether the MS compiler automatically looks into ../include or whether Visual Studio adds that path secretly, but it is a certain thing that the compiler cannot possibly find those files if it does not know where to look.
You don't need to add millions of paths for the same number of projects, since you can use relative pathnames, and if you don't like adding them to the individual projects, you can do so in global compiler options.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Michael

Quote from: troels on January 18, 2006, 02:26:15 PM
Quote from: Michael on January 18, 2006, 02:14:07 PM
After adding the include directories, I had to modify...

Sorry, buy this (gcctest.zip) is a perfectly valid project as is, I believe.
The idea is to not change anything. Especially not the source files.

Sorry, but I think it is not valid. If I add the include directories to C::B, then I have to modify as above, if I add no include directories, then I have to modify the #include in:


#include "./mylib/include/mylib.h"


The problem is when you give a relative path: from where begin the search?

Michael
[url="http://img207.imageshack.us/img207/9728/411948picture4em.png"]http://img207.imageshack.us/img207/9728/411948picture4em.png[/url]

troels

Quote from: Michael on January 18, 2006, 02:49:08 PM

#include "./mylib/include/mylib.h"

The problem is when you give a relative path: from where begin the search?

I believe it's fairly clear, apostrophes ("") means 'here' (the location of the .c file with the #include in it), lessthan-greaterthan (<>) means search include paths (first). But I could be wrong I guess.

Quote from: thomas on January 18, 2006, 02:45:07 PM
Quote from: troels on January 18, 2006, 02:26:15 PM
This is on purpose.
Well, on purpose or not, it's wrong ;)

It can't be entirely wrong, rightclicking -> "Build File" works.

/Troels

Michael

Quote from: troels on January 18, 2006, 02:56:31 PM
Quote from: Michael on January 18, 2006, 02:49:08 PM

#include "./mylib/include/mylib.h"

The problem is when you give a relative path: from where begin the search?

I believe it's fairly clear, apostrophes ("") means 'here' (the location of the .c file with the #include in it), lessthan-greaterthan (<>) means search include paths (first). But I could be wrong I guess.

Well, may be with VC++ 6. It works fine there. But with C::B not. May be a C::B dev can give some further info or instead confirms that I am wrong :).

Michael
[url="http://img207.imageshack.us/img207/9728/411948picture4em.png"]http://img207.imageshack.us/img207/9728/411948picture4em.png[/url]

thomas

#11
http://www.cppreference.com/preprocessor/include.html

EDIT:
The exact method supported by gcc is specified by C99, as described here: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf on page 149
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

TDragon

#12
Quote from: Michael on January 18, 2006, 02:49:08 PM
The problem is when you give a relative path: from where begin the search?
Spot on.

From what I've seen, the critical difference lies between specifying a qualified path (one with slashes) and a plain filename. For an include directive that only specifies a file name, GCC looks in the directory it was invoked from, the directory the file being compiled is in, and any additional directories specified with the -I option. For an include directive that specifies an absolute or relative qualified path, apparently it looks in the directory it was invoked from and any additional directories from the -I option, but NOT the directory the file being compiled is in. Code::Blocks calls GCC from the directory your .cbp file is in, so this is probably where your compilation is going wrong.
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

troels

Quote from: TDragon on January 18, 2006, 04:04:49 PM
...apparently it looks in the directory it was invoked from...but NOT the directory the file being compiled is in

Excellent! Thanks TDragon!

I've posted a bug report, #1409127.

Regards
Troels

TDragon

Now that I've posted all that, I'm not so sure anymore; look at the directory structure for one of my projects:

Cklo
|- Source
     |- Engine
     |   |- Engine.cpp {#include "../base.h"}
     |- base.h


Engine.cpp compiles without adding the "Engine" directory to the include paths. So my answer before appears to be wrong.
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)