Using the Standard Library with C++ Interop
Adam D. Ruppe
destructionator at gmail.com
Fri Feb 5 21:11:20 UTC 2021
On Friday, 5 February 2021 at 21:04:00 UTC, wolfiesnotfine wrote:
> however sse() from core.cpuid is incorrectly reporting as
> false. The function properly returns true if it's not called
> from C++ but instead a D main function.
That makes me think it is a static constructor, and indeed there
is one here:
https://github.com/dlang/druntime/blob/master/src/core/cpuid.d#L1068
Static constructors are normally run during druntime
initialization, but betterC never uses druntime and thus doesn't
initialize it.
You might be able to just call that function directly with some
pragma(mangle) hacks (get the symbol name out of the binary,
probably something like _D4core5cpuid6__ctor or something along
those lines, then declare function like `pragma(mangle, "that
name") extern void initCpuId();` and just call it at some point),
or copy/paste the source out into your code and call it that way.
The copy/paste is surely easier and more likely to work since
even if you get the symbol name, it probably isn't linked in with
-betterC since that skips linking the runtime code entirely.
tbh I'd say just don't use betterC, you can still runtime init
from C++ and be judicious in what features you use to keep it
more minimal.
More information about the Digitalmars-d-learn
mailing list