macOS 12, DMD 2.084.0 / LDC 1.14.0-beta1
I have a C API that exports some global variables, declared like
so:
.h file:
=====
extern "C" {
#define PUBLIC_API __attribute__((visibility("default")))
struct __opaqueHandle; typedef __opaqueHandle* opaqueHandle_t;
PUBLIC_API extern const opaqueHandle_t kSomeGlobalValue;
}
.cpp file:
======
const opaqueHandle_t kSomeGlobalValue = (opaqueHandle_t)
kSomeInternalPointer;
.d file:
====
extern (C):
export extern __gshared opaqueHandle_t kSomeGlobalValue;
I have no issues linking against the resulting .dylib with a
C/C++ program, nor issues with DMD on Windows with the same code.
However with DMD on macOS, the value is coming through
incorrectly. It looks like a valid pointer value (vs. pure
garbage), but it's still incorrect. LDC2 works fine, no issues.
Is there some extra flag I need to pass to DMD on Mac to get it
to see this global properly? It links fine, no errors, but the
value is still wrong. I should also mention that this dylib
exports functions, too, and they are working fine even with DMD.
It's just the globals I'm having problems with.