Just starting with D (linking with C++)

2017-10-27 Thread sivakon via Digitalmars-d-learn

Hi,

Just started to work with D. Great language.

I want to use C++ libraries for machine learning and deep 
learning. How do I add C++ libraries to my d code.


For example,

//sample.cpp
#include 

using namespace std;

int foo(int i, int j, int k)
{
cout << "i = " << i << endl;
cout << "j = " << j << endl;
cout << "k = " << k << endl;

return 7;
}


//foo.d
extern (C++) int foo(int i, int j, int k);

void main()
{
foo(1,2,3);
}


How do I compile and link each of them to produce the result?
dmd -c foo.d
gcc -c Sample.cpp

Both of them get me .o files. Where do I go from there?

Thanks,
Siv





Re: Just starting with D (linking with C++)

2017-10-27 Thread sivakon via Digitalmars-d-learn

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'


Re: Just starting with D (linking with C++)

2017-10-28 Thread sivakon via Digitalmars-d-learn

On Saturday, 28 October 2017 at 02:20:42 UTC, codephantom wrote:

On Friday, 27 October 2017 at 17:14:20 UTC, sivakon wrote:
I want to use C++ libraries for machine learning and deep 
learning. How do I add C++ libraries to my d code.


on FreeBSD, I use:

for C static binding:
--
clang -c sample.c

dmd -L-lc foo.d sample.o
or
ldc -L-lc foo.d sample.o


for c++ static binding:
---
clang++ -c sample.cpp

dmd -L-lc++ foo.d sample.o
or
ldc -L-lc++ foo.d sample.o


There is nice article here that was pretty interesting too:
https://www.gamedev.net/blogs/entry/2254003-binding-d-to-c/


Thanks! That worked like a charm. Now I can use dlang 
confidently. Any tips to make it faster cflags etc.


Using PyD

2017-11-21 Thread sivakon via Digitalmars-d-learn
I can create a python project by creating a PyDobject and `python 
setup.py install` and get the output.


If I want to add an external library in D (usually I do that with 
`dub run --single` command), how do I accomplish that?


In the project below, if I want to use some D libraries, how do I 
build it?

https://github.com/ariovistus/pyd/tree/master/examples/hello

Thanks,
Siva