www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linking 2 c++ libraries with D

reply "Milvakili" <maliy.kayit gmail.com> writes:
I have successfully link c++ with D.

Have ever when I create a dependency:
cpp2->cpp1->d

when compile with dmd

dmd cpp1.a cpp2.a file.d -L-lstdc++

It compiles but when I run it I get

relocation error: "some path": symbol _ZNSsC1EPKcRKSaIcE, version 
GLIBCXX_3.4 not defined in file libstdc++.so.6 with link time 
reference

When I replace the string variable of bar2 in cbin2.cpp  with an 
interger, code runs.

here is the files:

****dfile***
import std.stdio;
extern (C++) void foo(int i, int j, int k) {
   writefln("i = %s", i);
   writefln("j = %s", j);
   writefln("k = %s", k);
   writefln("looks ok");
}

extern (C++) void bar();

void main(){
   writeln("Testing callinf C++ main from D\n");
   bar();
}
****cbin.cpp***
#include <vector>
#include <iostream>
using namespace std;
void bar2(string i);

void bar(){
   bar2("cbin.cpp");
   printf("PRINTF:In cbin code\n");
}
****cbin2.cpp
#include <vector>
#include <iostream>

using namespace std;

void bar2(string s){
   cout << "cbin2 c++ library called from:" << s;
}
Jun 27 2013
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Friday, 28 June 2013 at 01:12:11 UTC, Milvakili wrote:
 relocation error: "some path": symbol _ZNSsC1EPKcRKSaIcE, 
 version GLIBCXX_3.4 not defined in file libstdc++.so.6 with 
 link time reference

did you compile the C++ and run the program on the same computer? This is complaining that it couldn't find the specific version of std::basic_string it was looking for in the c++ standard lib.
Jun 27 2013
prev sibling next sibling parent "Milvakili" <maliy.kayit gmail.com> writes:
On Friday, 28 June 2013 at 01:39:49 UTC, Adam D. Ruppe wrote:
 On Friday, 28 June 2013 at 01:12:11 UTC, Milvakili wrote:
 relocation error: "some path": symbol _ZNSsC1EPKcRKSaIcE, 
 version GLIBCXX_3.4 not defined in file libstdc++.so.6 with 
 link time reference

did you compile the C++ and run the program on the same computer? This is complaining that it couldn't find the specific version of std::basic_string it was looking for in the c++ standard lib.

Yes everything is on same computer and the library.
Jun 27 2013
prev sibling next sibling parent "Milvakili" <maliy.kayit gmail.com> writes:
On Friday, 28 June 2013 at 01:42:35 UTC, Milvakili wrote:
 On Friday, 28 June 2013 at 01:39:49 UTC, Adam D. Ruppe wrote:
 On Friday, 28 June 2013 at 01:12:11 UTC, Milvakili wrote:
 relocation error: "some path": symbol _ZNSsC1EPKcRKSaIcE, 
 version GLIBCXX_3.4 not defined in file libstdc++.so.6 with 
 link time reference

did you compile the C++ and run the program on the same computer? This is complaining that it couldn't find the specific version of std::basic_string it was looking for in the c++ standard lib.

Yes everything is on same computer and the library.

When I changed the string to vector<int> it still runs. Error is specific to string, current
Jun 27 2013
prev sibling next sibling parent Juan Manuel Cabo <juanmanuel.cabo gmail.com> writes:
On 06/27/2013 10:12 PM, Milvakili wrote:
 I have successfully link c++ with D.
 
 Have ever when I create a dependency:
 cpp2->cpp1->d
 
 when compile with dmd
 
 dmd cpp1.a cpp2.a file.d -L-lstdc++

I tried it and it works _perfectly_ for me, but instead of .a I compiled the C++ files to .o g++ -c cpp1.cpp g++ -c cpp2.cpp dmd cpp1.o cpp2.o file.d -L-lstdc++ (I had to comment the printf in cpp1.cpp) Running the program prints this output: Testing callinf C++ main from D cbin2 c++ library called from:cbin.cpp I'm on Kubuntu 12.04 64bits, using DMD v2.063.2 I have the following libstdc++ packages installed As shown by dpkg -l libstd*|grep ^ii libstdc++6 4.6.3-1ubuntu5 libstdc++6-4.4-dev 4.4.7-1ubuntu2 libstdc++6-4.6-dev 4.6.3-1ubuntu5 G++ version is: g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 ldd on the executable shows that it's using these libraries: linux-vdso.so.1 => (0x00007fff989ff000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9c0cbb7000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9c0c99a000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9c0c791000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9c0c57b000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c0c1bc000) /lib64/ld-linux-x86-64.so.2 (0x00007f9c0cedb000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9c0bebf000) Hope that any of this was useful to you! --jm
Jun 27 2013
prev sibling next sibling parent "Milvakili" <maliy.kayit gmail.com> writes:
On Friday, 28 June 2013 at 02:34:01 UTC, Juan Manuel Cabo wrote:
 On 06/27/2013 10:12 PM, Milvakili wrote:
 I have successfully link c++ with D.
 
 Have ever when I create a dependency:
 cpp2->cpp1->d
 
 when compile with dmd
 
 dmd cpp1.a cpp2.a file.d -L-lstdc++

I tried it and it works _perfectly_ for me, but instead of .a I compiled the C++ files to .o g++ -c cpp1.cpp g++ -c cpp2.cpp dmd cpp1.o cpp2.o file.d -L-lstdc++ (I had to comment the printf in cpp1.cpp) Running the program prints this output: Testing callinf C++ main from D cbin2 c++ library called from:cbin.cpp I'm on Kubuntu 12.04 64bits, using DMD v2.063.2 I have the following libstdc++ packages installed As shown by dpkg -l libstd*|grep ^ii libstdc++6 4.6.3-1ubuntu5 libstdc++6-4.4-dev 4.4.7-1ubuntu2 libstdc++6-4.6-dev 4.6.3-1ubuntu5 G++ version is: g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 ldd on the executable shows that it's using these libraries: linux-vdso.so.1 => (0x00007fff989ff000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9c0cbb7000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9c0c99a000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9c0c791000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9c0c57b000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c0c1bc000) /lib64/ld-linux-x86-64.so.2 (0x00007f9c0cedb000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9c0bebf000) Hope that any of this was useful to you! --jm

interesting thing is the code is working with same libraries when we have one dependency.
Jun 27 2013
prev sibling parent "Milvakili" <maliy.kayit gmail.com> writes:
On Friday, 28 June 2013 at 04:21:19 UTC, Milvakili wrote:
 On Friday, 28 June 2013 at 02:34:01 UTC, Juan Manuel Cabo wrote:
 On 06/27/2013 10:12 PM, Milvakili wrote:
 I have successfully link c++ with D.
 
 Have ever when I create a dependency:
 cpp2->cpp1->d
 
 when compile with dmd
 
 dmd cpp1.a cpp2.a file.d -L-lstdc++

I tried it and it works _perfectly_ for me, but instead of .a I compiled the C++ files to .o g++ -c cpp1.cpp g++ -c cpp2.cpp dmd cpp1.o cpp2.o file.d -L-lstdc++ (I had to comment the printf in cpp1.cpp) Running the program prints this output: Testing callinf C++ main from D cbin2 c++ library called from:cbin.cpp I'm on Kubuntu 12.04 64bits, using DMD v2.063.2 I have the following libstdc++ packages installed As shown by dpkg -l libstd*|grep ^ii libstdc++6 4.6.3-1ubuntu5 libstdc++6-4.4-dev 4.4.7-1ubuntu2 libstdc++6-4.6-dev 4.6.3-1ubuntu5 G++ version is: g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 ldd on the executable shows that it's using these libraries: linux-vdso.so.1 => (0x00007fff989ff000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9c0cbb7000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9c0c99a000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9c0c791000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9c0c57b000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c0c1bc000) /lib64/ld-linux-x86-64.so.2 (0x00007f9c0cedb000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9c0bebf000) Hope that any of this was useful to you! --jm

interesting thing is the code is working with same libraries when we have one dependency.

I fix the problem by using the os standard libraries.
Jun 28 2013