public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Compiling modules: understanding filename conventions
@ 2023-05-05  5:08 Wilhelm Meier
  2023-05-05  7:36 ` Jonathan Wakely
  2023-05-05  7:41 ` Jonathan Wakely
  0 siblings, 2 replies; 4+ messages in thread
From: Wilhelm Meier @ 2023-05-05  5:08 UTC (permalink / raw)
  To: gcc-help

Hi all,

I think, I have some misconceptions about compiling modules :-(

Say, I have a module interface unit modA.hxx and a module implementation 
unit modA.cxx for module A. If I compile modA.hxx I get the bmi in 
gcm.cache and a file modA.o. I need the bmi to compile the modA.cxx, but 
this overrides modA.o. This does not harm, since modA.o from modA.hxx 
looks more or less empty. Linking with the (overridden) file modA.o does 
work.

If I compile modA.hxx to modA_h.o and modA.cxx to modA_i.o  and use 
these two files for linking, it works as well. And if I only use 
modA_i.o, it also works.

So, what is the intent to compile a module interface unit also to a .o 
file? In my understanding it should only generate a bmi file.

Additionally, if I have some modules in different directories but with 
same file-names, the files in gcm.cache resemble that directory 
structure, but the .o files are overridden.

Looks like I do not understand haw to compile modules....

Thanks in advance,
  Wilhelm


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiling modules: understanding filename conventions
  2023-05-05  5:08 Compiling modules: understanding filename conventions Wilhelm Meier
@ 2023-05-05  7:36 ` Jonathan Wakely
  2023-05-05  8:24   ` Wilhelm Meier
  2023-05-05  7:41 ` Jonathan Wakely
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2023-05-05  7:36 UTC (permalink / raw)
  To: Wilhelm Meier; +Cc: gcc-help

On Fri, 5 May 2023 at 06:09, Wilhelm Meier wrote:
>
> Hi all,
>
> I think, I have some misconceptions about compiling modules :-(
>
> Say, I have a module interface unit modA.hxx and a module implementation
> unit modA.cxx for module A. If I compile modA.hxx I get the bmi in
> gcm.cache and a file modA.o. I need the bmi to compile the modA.cxx, but
> this overrides modA.o. This does not harm, since modA.o from modA.hxx
> looks more or less empty. Linking with the (overridden) file modA.o does
> work.

A module interface unit is not a header, so there's no reason to use a
.hxx extension. So if you name them something like modA_intf.cxx and
modA_impl.cxx then you avoid the problem.

You can also use -fmodule-only to inhibit creation of the .o file (GCC
doesn't know whether you intend to compile a module interface unit or
a module implementation unit, so it treats them the same and assumes
you want a linkable .o file).

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiling modules: understanding filename conventions
  2023-05-05  5:08 Compiling modules: understanding filename conventions Wilhelm Meier
  2023-05-05  7:36 ` Jonathan Wakely
@ 2023-05-05  7:41 ` Jonathan Wakely
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2023-05-05  7:41 UTC (permalink / raw)
  To: Wilhelm Meier; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 454 bytes --]

On Fri, 5 May 2023, 06:09 Wilhelm Meier wrote:

>
> Additionally, if I have some modules in different directories but with
> same file-names, the files in gcm.cache resemble that directory
> structure, but the .o files are overridden.
>

This is exactly the same as doing:
g++ -c dir1/foo.cc
g++ -c dir2/foo.cc

So not anything specific to modules.

If you don't want foo.o to be overridden, you can use -o to write to
dir1/foo.o or some other location.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Compiling modules: understanding filename conventions
  2023-05-05  7:36 ` Jonathan Wakely
@ 2023-05-05  8:24   ` Wilhelm Meier
  0 siblings, 0 replies; 4+ messages in thread
From: Wilhelm Meier @ 2023-05-05  8:24 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-help

On 05.05.23 09:36, Jonathan Wakely wrote:
> On Fri, 5 May 2023 at 06:09, Wilhelm Meier wrote:
>>
>> Hi all,
>>
>> I think, I have some misconceptions about compiling modules :-(
>>
>> Say, I have a module interface unit modA.hxx and a module implementation
>> unit modA.cxx for module A. If I compile modA.hxx I get the bmi in
>> gcm.cache and a file modA.o. I need the bmi to compile the modA.cxx, but
>> this overrides modA.o. This does not harm, since modA.o from modA.hxx
>> looks more or less empty. Linking with the (overridden) file modA.o does
>> work.
> 
> A module interface unit is not a header, so there's no reason to use a
> .hxx extension. So if you name them something like modA_intf.cxx and
> modA_impl.cxx then you avoid the problem.

Ok, make much more sense!
Especially because module interface units may safely contain definitions.

> You can also use -fmodule-only to inhibit creation of the .o file (GCC
> doesn't know whether you intend to compile a module interface unit or
> a module implementation unit, so it treats them the same and assumes
> you want a linkable .o file).

So, if all entities in the module interface unit are (implicitly) 
inline, one can safely use -fmodule-only?

I think, that would be best strategie to convert a header-only library.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-05  8:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05  5:08 Compiling modules: understanding filename conventions Wilhelm Meier
2023-05-05  7:36 ` Jonathan Wakely
2023-05-05  8:24   ` Wilhelm Meier
2023-05-05  7:41 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).