<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi,<br>
I think there's more to it.</p>
<p>On Linux, if I do the following:</p>
<p>```<br>
$ cat foo.h<br>
int i = 4;<br>
```<br>
</p>
<p>and:</p>
<p>```<br>
$ cat foo.c<br>
#include "foo.h"<br>
```<br>
</p>
<p>And then I compile into a shared lib, the obtained foo.so does
have a symbol for "i" (rightfully so):<br>
</p>
<p>```<br>
$ objdump -T foo.so<br>
<br>
foo.so: file format elf64-x86-64<br>
<br>
DYNAMIC SYMBOL TABLE:<br>
0000000000000000 w D *UND* 0000000000000000 __cxa_finalize<br>
0000000000000000 w D *UND* 0000000000000000
_ITM_registerTMCloneTable<br>
0000000000000000 w D *UND* 0000000000000000
_ITM_deregisterTMCloneTable<br>
0000000000000000 w D *UND* 0000000000000000 __gmon_start__<br>
0000000000004020 g DO .data 0000000000000004 i<br>
<br>
```</p>
<p>E.g. the above header contains a *definition*, so the compiler
will create storage for it (and add it to the shared library), and
"i" can be looked up in the shared lib. Conversely, a global
marked as "extern" might or might not be present in the shared
library (depending on whether it's defined in one of the
associated C/CPP files).<br>
</p>
<p>Maurizio<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 06/09/2022 13:57, Manuel
Bleichenbacher wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAA7F5jLaXkpmdyxg1BfOTgD0dp+Eeq0pVu-0jU+1pez_gC-YMg@mail.gmail.com">
<div dir="ltr">
<div>There are two indications that it's definition and not a
declaration:</div>
<div><br>
</div>
<div>- absence of "extern" keyword</div>
<div>- presence of initialization ( = { 0x... )</div>
<div><br>
</div>
<div>If it was compiled as C/C++ code, it would allocate memory
in the current compilation unit while a declaration would just
refer to something outside the compilation unit.</div>
<div><br>
</div>
<div>Definitions are rare in header files as they usually lead
to duplicate symbol errors at link time. But through the magic
of __declspec(selectany), this is avoided.
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Sep 6, 2022 at 12:11
PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" moz-do-not-send="true" class="moz-txt-link-freetext">maurizio.cimadamore@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 05/09/2022 16:32, Manuel Bleichenbacher wrote:<br>
> extern "C" const GUID __declspec(selectany)
GUID_DEVINTERFACE_USB_DEVICE<br>
> = { 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00,
0xC0, <br>
> 0x4F, 0xB9, 0x51, 0xED } };<br>
><br>
I guess the problem here is the lack of "dllexport", right?<br>
<br>
But, while dllexport is common, some libraries can still
export symbols <br>
using a .def file [1].<br>
<br>
So, I'm not sure this belongs in the same category as "static
inline", <br>
as it is not possible, just by looking at the header, to
understand <br>
whether the symbol will be present or not?<br>
<br>
[1] - <br>
<a href="https://urldefense.com/v3/__https://docs.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-def-files?view=msvc-170__;!!ACWV5N9M2RV99hQ!IZ9OZ1GPWyZCLxdiYrnGJewYmhC_BCpH8sxH4Lo2jBtSsuMJPH_j3-vIXRO1emIKo2SMrT3Sj1AqI3daPLx2VOq6oGrpPgb-Xw$" rel="noreferrer" target="_blank" moz-do-not-send="true">https://docs.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-def-files?view=msvc-170</a><br>
<br>
</blockquote>
</div>
</blockquote>
</body>
</html>