Author Topic: Moving to GCC question  (Read 39297 times)

Offline troels

  • Multiple posting newcomer
  • *
  • Posts: 71
Moving to GCC question
« on: January 18, 2006, 01:08:16 pm »
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

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Moving to GCC question
« Reply #1 on: January 18, 2006, 01:15:38 pm »
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...

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Moving to GCC question
« Reply #2 on: January 18, 2006, 01:17:16 pm »
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."

Offline troels

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Moving to GCC question
« Reply #3 on: January 18, 2006, 01:43:03 pm »
Check that whatever it is you try to include really exists...

It certainly does. It compiles in MSVC.

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

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Moving to GCC question
« Reply #4 on: January 18, 2006, 02:14:07 pm »
After adding the include directories, I had to modify the #include (mylib\src\mylib.c) in:

Code
#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

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Moving to GCC question
« Reply #5 on: January 18, 2006, 02:21:17 pm »
It 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."

Offline troels

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Moving to GCC question
« Reply #6 on: January 18, 2006, 02:26:15 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.

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
« Last Edit: January 18, 2006, 02:35:55 pm by troels »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Moving to GCC question
« Reply #7 on: January 18, 2006, 02:45:07 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."

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Moving to GCC question
« Reply #8 on: January 18, 2006, 02:49:08 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:

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

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

Michael

Offline troels

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Moving to GCC question
« Reply #9 on: January 18, 2006, 02:56:31 pm »
Code
#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.

This is on purpose.
Well, on purpose or not, it's wrong ;)

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

/Troels

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Moving to GCC question
« Reply #10 on: January 18, 2006, 03:01:19 pm »
Code
#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
 

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Moving to GCC question
« Reply #11 on: January 18, 2006, 04:00:45 pm »
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
« Last Edit: January 18, 2006, 04:07:41 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Moving to GCC question
« Reply #12 on: January 18, 2006, 04:04:49 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.
« Last Edit: January 18, 2006, 04:07:32 pm by TDragon »
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline troels

  • Multiple posting newcomer
  • *
  • Posts: 71
Re: Moving to GCC question
« Reply #13 on: January 18, 2006, 04:21:10 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

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Moving to GCC question
« Reply #14 on: January 18, 2006, 04:36:34 pm »
Now that I've posted all that, I'm not so sure anymore; look at the directory structure for one of my projects:
Code
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.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)