D and C++ undefined reference when namespace

Markus contact at markus-lanner.com
Thu Mar 8 16:35:51 UTC 2018


On Thursday, 8 March 2018 at 16:19:40 UTC, Steven Schveighoffer 
wrote:
> On 3/8/18 10:27 AM, Markus wrote:
>> Hi
>> 
>> I got the following c++ code [lib.cpp]:
>> namespace ns_a
>> {
>>    class class_a {
>>    };
>>    void some_function(class_a*) {;}
>> }
>> 
>> and the following d code [main.d]:
>> extern (C++, namespace_a) {
>
> did you mean ns_a?
>
> -Steve

yes, that's clearly the issue in my first post. :) I failed when 
I made a minimal sample for this forum

[lib.cpp]:
namespace ns_a
{
   class class_a {
   };
   void some_function(class_a*) {;}
}

[other.d]:
extern (C++, ns_a) {
     class class_a {}
}

[main.d]:
import other;
extern (C++, ns_a) {
     void some_function(class_a);
}
void main() {
     class_a instance_a;
     ns_a.some_function(instance_a);
}

compilation:
g++ -shared lib.cpp -o libissue.so
dmd main.d -L-lissue -L-L.

error:
main.o: In function `_Dmain':
main.d:(.text._Dmain[_Dmain]+0xa): undefined reference to 
`ns_a::some_function(ns_a::class_a*)'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

symbols:
nm --demangle libissue.so | some_function
000000000000059a T ns_a::some_function(ns_a::class_a*)

It doesn't seem like an error, but it is.
I still don't get it, whey I'm not allowed to split the namespace 
declarations.



More information about the Digitalmars-d mailing list