You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I reference cpp_interface,calling C++ Global Functions from D but link error when compile c++ source in c++20 module syntax as library.
app.d source file content
module app ;
importstd.stdio;
extern (C++,dmd) int foo(int i, int j, int k);
voidmain()
{
auto x = foo(1, 2, 3);
writeln(x);
}
compile foo.cppm with cmake , generate libfoo.so
add_library(geo SHARED)
target_sources(geo PUBLIC
FILE_SET CXX_MODULES FILES${CMAKE_SOURCE_DIR}/src/geo.cppm
)
// foo.cppm
module;
#include<iostream>export module Test;
usingnamespacestd;exportnamespacedetail {
intfoo(int i, int j, int k) {
cout << "i = " << i << endl;
cout << "j = " << j << endl;
cout << "k = " << k << endl;
return7;
}
} // namespace detailexportnamespacedmd {
intfoo(int i, int j, int k) {
cout << "i = " << i + 100 << endl;
cout << "j = " << j + 200 << endl;
cout << "k = " << k + 300 << endl;
return20;
}
} // namespace detail
when use dub build to link ,gave the error
undefined reference to `dmd::foo(int, int, int)'clang-18: error: linker command failed with exit code 1 (use -v to see invocation)Error: undefined reference to `dmd::foo(int, int, int)` perhaps a library needs to be added with the `-L` flag or `pragma(lib, ...)`
dump name symbol
╰─ llvm-nm-18 -C build/libgeo.so |grep foo
0000000000001260 T dmd::foo@Test(int, int, int)
00000000000011b0 T detail::foo@Test(int, int, int)
The text was updated successfully, but these errors were encountered:
pengybhnu
changed the title
support c++ 20 module name mangling
How to support c++ 20 module name mangling when Interfacing to C++?
Jan 6, 2025
As a workaround you might try to see if pragma(mangle, <the_right_thing_as_a_string>) is of any help. But clearly even if it appears that this works, that does not scale, i.e not a good general solution.
As a workaround you might try to see if pragma(mangle, <the_right_thing_as_a_string>) is of any help. But clearly even if it appears that this works, that does not scale, i.e not a good general solution.
thanks, it works! may be better if extern (C++,<namespace>,<c++ module name>) syntax supported by compiler
pragma(mangle, "_ZN3dmdW4Test3fooEiii")
extern (C++) int foo(int i, int j, int k);
llvm-nm-18 build/libgeo.so |grep foo
00000000000012e0 T _ZN3dmdW4Test3fooEiii
0000000000001230 T _ZN6detailW4Test3fooEiii
I reference cpp_interface,calling C++ Global Functions from D but link error when compile c++ source in c++20 module syntax as library.
app.d source file content
compile foo.cppm with cmake , generate libfoo.so
when use dub build to link ,gave the error
dump name symbol
╰─ llvm-nm-18 -C build/libgeo.so |grep foo 0000000000001260 T dmd::foo@Test(int, int, int) 00000000000011b0 T detail::foo@Test(int, int, int)
The text was updated successfully, but these errors were encountered: