Just starting with D (linking with C++)

Steven Schveighoffer schveiguy at yahoo.com
Fri Oct 27 18:18:44 UTC 2017


On 10/27/17 1:43 PM, sivakon wrote:
> On Friday, 27 October 2017 at 17:21:39 UTC, Joakim wrote:
>>
>> This should work:
>>
>> dmd foo.d Sample.o
>>
>> Just like the C examples from the D blog:
>>
>> https://dlang.org/blog/2017/10/25/dmd-windows-and-c/
> 
> Just used this! Got this error!
> 
> sample.o: In function `foo(int, int, int)':
> sample.cpp:(.text+0x17): undefined reference to `std::cout'

You need to link against the C++ standard library. On my system, it 
appears to be -lc++.

So in order to pass this value to the linker, use the dmd parameter -L-lc++

In order to find out what the name of the c++ library is, you need to 
compile a C++ program with the -v option. The linker step will show the 
library parameters you need to send to dmd.

-Steve


More information about the Digitalmars-d-learn mailing list