October 13, 2015
On Tuesday, 13 October 2015 at 13:57:15 UTC, Meta wrote:
> On Tuesday, 13 October 2015 at 13:18:36 UTC, Kagamin wrote:
>> Well, in order to pass the result of a function call to a template parameter means that the function must be evaluated at compile time, which is not always possible, so it probably doesn't make sense to call a function when passed as a template argument.
>
> You'd be surprised what DMD thinks is a function call and what isn't.

What doesn't work for you?

extern int f();
struct T(F){}
T!f t; //Error: template instance T!(f) does not match template declaration T(F)
struct A(alias F){}
A!f a; //works
October 13, 2015
On Wednesday, 7 October 2015 at 22:33:09 UTC, Martin Nowak wrote:
> First beta for the 2.069.0 release.
>
> http://dlang.org/download.html#dmd_beta http://dlang.org/changelog/2.069.0.html
>
> Please report any bugs at https://issues.dlang.org
>
> -Martin

I decided to try the newly included mscoff 32 Phobos. For this purpouse I create a D struct, whose members I call in C++. This works in Linux, so any issues should be windows specific.

My directory has the following files:
test_struct.d
main.cpp

I did the following:
1) Installed DMD v2.069.0-b1 with the installer
2) Started VS2015 x86 Native Tools Command Prompt
3) Executed the following commands:
dmd -c -m32mscoff test_struct.d
cl main.cpp test_struct.obj C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib

And got the following error:
main.cpp
phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved exter
nal symbol __minfo_beg referenced in function _D2rt14sections_win6414getModuleIn
fosFZAyPS6object10ModuleInfo
phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved exter
nal symbol __minfo_end referenced in function _D2rt14sections_win6414getModuleIn
fosFZAyPS6object10ModuleInfo
phobos32mscoff.lib(config_48f_452.obj) : error LNK2019: unresolved external symb
ol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAx
aKfZb
phobos32mscoff.lib(config_48f_452.obj) : error LNK2019: unresolved external symb
ol _sscanf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaK
fZb
hw0_cpp.exe : fatal error LNK1120: 4 unresolved externals

I have declared the druntime hooks like this:
extern "C" int rt_init();
extern "C" void rt_term();

P.S. I decided to try something simpler:
A single .cpp file that calls rt_init() and rt_term() and nothing else. I tried the following:
cl main.cpp C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib
And I got the same error message.

Any idea what's going wrong?
October 13, 2015
On Tuesday, 13 October 2015 at 19:14:51 UTC, ZombineDev wrote:
> On Wednesday, 7 October 2015 at 22:33:09 UTC, Martin Nowak wrote:
>> First beta for the 2.069.0 release.
>>
>> http://dlang.org/download.html#dmd_beta http://dlang.org/changelog/2.069.0.html
>>
>> Please report any bugs at https://issues.dlang.org
>>
>> -Martin
>
> I decided to try the newly included mscoff 32 Phobos. For this purpouse I create a D struct, whose members I call in C++. This works in Linux, so any issues should be windows specific.
>
> My directory has the following files:
> test_struct.d
> main.cpp
>
> I did the following:
> 1) Installed DMD v2.069.0-b1 with the installer
> 2) Started VS2015 x86 Native Tools Command Prompt
> 3) Executed the following commands:
> dmd -c -m32mscoff test_struct.d
> cl main.cpp test_struct.obj C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib
>
> And got the following error:
> main.cpp
> phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved exter
> nal symbol __minfo_beg referenced in function _D2rt14sections_win6414getModuleIn
> fosFZAyPS6object10ModuleInfo
> phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved exter
> nal symbol __minfo_end referenced in function _D2rt14sections_win6414getModuleIn
> fosFZAyPS6object10ModuleInfo
> phobos32mscoff.lib(config_48f_452.obj) : error LNK2019: unresolved external symb
> ol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAx
> aKfZb
> phobos32mscoff.lib(config_48f_452.obj) : error LNK2019: unresolved external symb
> ol _sscanf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaK
> fZb
> hw0_cpp.exe : fatal error LNK1120: 4 unresolved externals

Edit - read this as:
main.exe : fatal error LNK1120: 4 unresolved externals

> I have declared the druntime hooks like this:
> extern "C" int rt_init();
> extern "C" void rt_term();
>
> P.S. I decided to try something simpler:
> A single .cpp file that calls rt_init() and rt_term() and nothing else. I tried the following:
> cl main.cpp C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib
> And I got the same error message.
>
> Any idea what's going wrong?


October 13, 2015
On Tuesday, 13 October 2015 at 19:17:27 UTC, ZombineDev wrote:
> On Tuesday, 13 October 2015 at 19:14:51 UTC, ZombineDev wrote:
> [...]

Is the problem related to the new CRT in VS2015? Previously I thought that the problem is 64-bit only, but it seams like it is for both 32-bit and 64-bit MSCOFF.

With the VS2015 x64 Native Tools Command Prompt I did:
cl main.cpp C:\D\dmd2\windows\lib64\phobos64.lib

And got:

main.cpp
phobos64.lib(sections_win64_6c9_5a5.obj) : error LNK2019: unresolved external sy
mbol _minfo_beg referenced in function _D2rt14sections_win6414getModuleInfosFZAy
PS6object10ModuleInfo
phobos64.lib(sections_win64_6c9_5a5.obj) : error LNK2019: unresolved external sy
mbol _minfo_end referenced in function _D2rt14sections_win6414getModuleInfosFZAy
PS6object10ModuleInfo
phobos64.lib(sections_win64_6c3_4e2.obj) : error LNK2019: unresolved external sy
mbol _deh_beg referenced in function _D2rt14sections_win6412SectionGroup8ehTable
sMxFNdZAyS2rt15deh_win64_posix9FuncTable
phobos64.lib(sections_win64_6c3_4e2.obj) : error LNK2019: unresolved external sy
mbol _deh_end referenced in function _D2rt14sections_win6412SectionGroup8ehTable
sMxFNdZAyS2rt15deh_win64_posix9FuncTable
phobos64.lib(config_48f_452.obj) : error LNK2019: unresolved external symbol snp
rintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb
phobos64.lib(config_48f_452.obj) : error LNK2019: unresolved external symbol ssc
anf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb
main.exe : fatal error LNK1120: 6 unresolved externals

AFAIR, the support for VS2015 CRT was merged and is included in this release, correct?
October 13, 2015

On 13.10.2015 21:44, ZombineDev wrote:
> On Tuesday, 13 October 2015 at 19:17:27 UTC, ZombineDev wrote:
>> On Tuesday, 13 October 2015 at 19:14:51 UTC, ZombineDev wrote:
>> [...]
>
> Is the problem related to the new CRT in VS2015? Previously I thought
> that the problem is 64-bit only, but it seams like it is for both 32-bit
> and 64-bit MSCOFF.

The library issues are the same for 32-bit and 64-bit.

>
> With the VS2015 x64 Native Tools Command Prompt I did:
> cl main.cpp C:\D\dmd2\windows\lib64\phobos64.lib
>
> And got:
>
> main.cpp
> phobos64.lib(sections_win64_6c9_5a5.obj) : error LNK2019: unresolved
> external sy
> mbol _minfo_beg referenced in function
> _D2rt14sections_win6414getModuleInfosFZAy
> PS6object10ModuleInfo
> phobos64.lib(sections_win64_6c9_5a5.obj) : error LNK2019: unresolved
> external sy
> mbol _minfo_end referenced in function
> _D2rt14sections_win6414getModuleInfosFZAy
> PS6object10ModuleInfo
> phobos64.lib(sections_win64_6c3_4e2.obj) : error LNK2019: unresolved
> external sy
> mbol _deh_beg referenced in function
> _D2rt14sections_win6412SectionGroup8ehTable
> sMxFNdZAyS2rt15deh_win64_posix9FuncTable
> phobos64.lib(sections_win64_6c3_4e2.obj) : error LNK2019: unresolved
> external sy
> mbol _deh_end referenced in function
> _D2rt14sections_win6412SectionGroup8ehTable
> sMxFNdZAyS2rt15deh_win64_posix9FuncTable
> phobos64.lib(config_48f_452.obj) : error LNK2019: unresolved external
> symbol snp
> rintf referenced in function
> _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb
> phobos64.lib(config_48f_452.obj) : error LNK2019: unresolved external
> symbol ssc
> anf referenced in function
> _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb
> main.exe : fatal error LNK1120: 6 unresolved externals
>
> AFAIR, the support for VS2015 CRT was merged and is included in this
> release, correct?

Yes, but there is some magic involved when linking against the VS2015 CRT. To use symbols like snprintf and sscanf, you must also pass legacy_stdio_definitions.lib to the linker, which is done automatically if you use dmd as a frontend to the linker, but not cl.

Symbols _minfo_beg, _minfo_end, _deh_beg and _deh_end are only emitted by the compiler if you compile main, WinMain or DllMain. Unfortunately, compiling D's main also generates a C-style main, so it's not so easy to get these symbols if you need main in C/C++.

I would currently recommend to write main in D, and call into C/C++ from there.
October 14, 2015
On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote:
>
>
> On 13.10.2015 21:44, ZombineDev wrote:
>> [...]
>
> The library issues are the same for 32-bit and 64-bit.
>
>> [...]
>
> Yes, but there is some magic involved when linking against the VS2015 CRT. To use symbols like snprintf and sscanf, you must also pass legacy_stdio_definitions.lib to the linker, which is done automatically if you use dmd as a frontend to the linker, but not cl.
>
> Symbols _minfo_beg, _minfo_end, _deh_beg and _deh_end are only emitted by the compiler if you compile main, WinMain or DllMain. Unfortunately, compiling D's main also generates a C-style main, so it's not so easy to get these symbols if you need main in C/C++.
>
> I would currently recommend to write main in D, and call into C/C++ from there.

I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue:

Error	2	error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb	C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj)	ConsoleApplication1

_minfo_beg, _minfo_end problems were solved by adding main() to D library so this is only porblem left. I am using Visual Studio 2012
October 14, 2015
On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote:
> Yes, but there is some magic involved when linking against the VS2015 CRT. To use symbols like snprintf and sscanf, you must also pass legacy_stdio_definitions.lib to the linker, which is done automatically if you use dmd as a frontend to the linker, but not cl.
>
> Symbols _minfo_beg, _minfo_end, _deh_beg and _deh_end are only emitted by the compiler if you compile main, WinMain or DllMain. Unfortunately, compiling D's main also generates a C-style main, so it's not so easy to get these symbols if you need main in C/C++.
>
> I would currently recommend to write main in D, and call into C/C++ from there.

Thanks for the answer.

Just for the reference, under VS2015 x86 Native Tools Command Prompt I tried to link a C++ main function that only calls rt_init() and rt_term() like this:

cl main.cpp C:\D\dmd2\windows\lib32mscoff\phobos32mscoff.lib "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\legacy_stdio_definitions.lib"

I got:
main.cpp
phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved external symbol __minfo_beg referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
phobos32mscoff.lib(sections_win64_6de_5a5.obj) : error LNK2019: unresolved external symbol __minfo_end referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
main.exe : fatal error LNK1120: 2 unresolved externals

Which, based on your answer, is expected.

I'm looking into integrating D into an existing C++ build and I need to statically link the D library. So my next questions are:
1) Where can I find legacy_stdio_definitions.lib?
P.S.: It's included in VS (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\legacy_stdio_definitions.lib)
2) How can I workaround the problem that _minfo* and _deh* are not generated because my main is in C++?

Basically what's preventing me from using D main is that one of the C++ libraries I use creates threads and dispatches functions to run on them in manner similar to Boost ASIO, and I don't have control over this proprietary library.

To me, the fact that consuming D libraries from C++ works on Linux, but not on Windows seems like a very serious issue with Windows support.

I know that this is work in progress and that VS 2015 broke the ABI of its CRT, and it's hard to track down those problems with every VS release, so let me know if I can help with anything. Currently I do not have enough knowledge tackle the problem, but I am willing to learn.
October 14, 2015
On Wednesday, 14 October 2015 at 11:46:27 UTC, ZombineDev wrote:

> 2) How can I workaround the problem that _minfo* and _deh* are not generated because my main is in C++?
>

Just add a file with int main() in D library to fix this.
October 14, 2015
On Wednesday, 14 October 2015 at 11:39:26 UTC, Szymon Gatner wrote:
> On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote:
>> [...]
>
> I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue:
>
> Error	2	error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb	C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj)	ConsoleApplication1
>
> _minfo_beg, _minfo_end problems were solved by adding main() to D library so this is only porblem left. I am using Visual Studio 2012

Update: Linking with static D library under Visual Studio 2015 works fine (which is great). I do need to make it work under VS 2012 tho. Ideas?
October 14, 2015
On Wednesday, 14 October 2015 at 12:05:28 UTC, Szymon Gatner wrote:
> On Wednesday, 14 October 2015 at 11:39:26 UTC, Szymon Gatner wrote:
>> On Tuesday, 13 October 2015 at 20:10:22 UTC, Rainer Schuetze wrote:
>>> [...]
>>
>> I am trying (as with every new release ;)) to link static D library to existing C++ project and I am having same issue:
>>
>> Error	2	error LNK2019: unresolved external symbol _snprintf referenced in function _D2gc6config13__T5parseHTfZ5parseFNbNiAxaKAxaKfZb	C:\Users\Bravo\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\phobos32mscoff.lib(config_48f_452.obj)	ConsoleApplication1
>>
>> _minfo_beg, _minfo_end problems were solved by adding main() to D library so this is only porblem left. I am using Visual Studio 2012
>
> Update: Linking with static D library under Visual Studio 2015 works fine (which is great). I do need to make it work under VS 2012 tho. Ideas?

Another Update: a bug I reported many moons ago is still there when mixing C++ with D. I updated the issue: https://issues.dlang.org/show_bug.cgi?id=14327