Re: struggling to link against a C global in D (win/vs2017)

2018-10-29 Thread 12345swordy via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:16:38 UTC, Stanislav Blinov wrote: On Monday, 29 October 2018 at 00:01:21 UTC, DanielG wrote: In my D app I'm declaring it this way: extern (C) { extern __gshared int myIntValue; int myIntFunc (int a, int b); } The function seems to link OK,

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread DanielG via Digitalmars-d-learn
On Monday, 29 October 2018 at 01:03:32 UTC, kinke wrote: export extern(C) extern __gshared int myIntValue; Bingo!! That did the trick. Thank you so much.

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread kinke via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:01:21 UTC, DanielG wrote: DLLPROJECT_API I guess that's a __declspec(dllexport); in that case try export extern(C) extern __gshared int myIntValue; => that's dllimport for extern variables, and dllexport for non-extern ones.

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread kinke via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:52:32 UTC, kinke wrote: The names it spits out are undecorated Correction: they *are* the decorated ones, i.e., the real final names.

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread kinke via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:01:21 UTC, DanielG wrote: [...] I'd examine the dumpbin output of your (native) import library, e.g., `dumpbin /symbols blub.lib`. You can also list exports etc. The names it spits out are undecorated, i.e., C symbols for Win32 libs will feature the implicit

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:12:43 UTC, DanielG wrote: It's defined in the .cpp file. Ah, of course, good. The other thing that might be an issue is the leading _ the compiler frequently adds. You might be able to hack it with pragma(mangle, "myIntValue") on the declaration too. idk for

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread DanielG via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:16:38 UTC, Stanislav Blinov wrote: Should it be extern(Windows), perchance?.. (I haven't D on Windows for ages). The stdcall calling convention? I think that would only matter for the function, and indeed, trying that breaks the function being able to link**

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:01:21 UTC, DanielG wrote: In my D app I'm declaring it this way: extern (C) { extern __gshared int myIntValue; int myIntFunc (int a, int b); } The function seems to link OK, but the C global will not. Should it be extern(Windows),

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread DanielG via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:04:54 UTC, Adam D. Ruppe wrote: Both are listed as extern, where is the actual variable stored? If it is in the dll, it shouldn't be extern there. It's defined in the .cpp file. This is how the built-in DLL template generates it - "extern" in the .h file,

Re: struggling to link against a C global in D (win/vs2017)

2018-10-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 29 October 2018 at 00:01:21 UTC, DanielG wrote: extern DLLPROJECT_API int myIntValue; extern __gshared int myIntValue; Both are listed as extern, where is the actual variable stored? If it is in the dll, it shouldn't be extern there.