Linking external functions?

ag0aep6g anonymous at example.com
Tue Apr 18 20:27:59 UTC 2023


On Tuesday, 18 April 2023 at 20:05:05 UTC, DLearner wrote:
> Is the declaration inside main not visible to the linker?

It affects the (fully qualified and mangled) name of the 
function. Compare:

```d
extern(C) void ExtCallee();
pragma(msg, ExtCallee.mangleof); /* ExtCallee (correct name) */
void main()
{
     extern(C) void ExtCallee();
     pragma(msg, ExtCallee.mangleof); /* 
_D7ExtMain4mainFZ9ExtCalleeUZv (incorrect) */
}
```

I don't know the rationale behind that behavior, if there is one. 
Generally, just put your `extern(C)` prototypes in module scope.


More information about the Digitalmars-d-learn mailing list