c++g++ldd

ld: undefined reference to object I can see in objdump


I am doing some unorthodox linking right now and predictably enough I encountered some issues. However I have gone through all the usual subjects and the problem persists.
I have a D source file defining a class

extern (C++){
    class motionFactory{
        public:
            this(double velocity, double gravity, double angle){
                this.velocity = velocity;
                this.gravity = gravity;
                this.angle = angle;
            }
     }
}

That I then access in C++ using this .hpp file (according to the D documentation this is perfectly legal)

class motionFactory {
    public:
        motionFactory(double velocity, double gravity, double angle);
}

And then inherit from this class like this:

class motionGraph : public wxBitmap, public motionFactory{
    public:
        motionGraph(double velocity, double gravity, double angle, int width, int height);
}

During compilation however I encounter a link error stating that the constructor for motionFactory is undefined.

/usr/bin/ld: motionGraph.o: in function `motionGraph::motionGraph(double, double, double, int, int)':
motionGraph.cpp:(.text+0x66): undefined reference to `motionFactory::motionFactory(double, double, double)'

I compile like this:

gdc -r D/motion.d ballistics.o -o motion.o $(CFLAGS) -lgphobos -J fortran
g++ -c gui/motionGraph.cpp -o motionGraph.o $(CFLAGS) $(wxFlags)
g++ gui/main.cpp motionGraph.o motion.o mainFrame.o -o guiCalculator -lm $(CFLAGS) $(wxFlags)

I find this quite weird because in previous versions of the code I was constructing motionFactories in c++ just fine, and what's more objdump says that the constructor is there

compiled D file objdump:

000000000000039c g     F .text  0000000000000047 motionFactory::motionFactory(double, double, double)

compiled c++ file objdump:

0000000000000000 g     F .text  0000000000000177 motionGraph::motionGraph(double, double, double, int, int)
0000000000000000         *UND*  0000000000000000 motionFactory::motionFactory(double, double, double)
0000000000000000  w    O .data.rel.ro._ZTV11motionGraph 0000000000000108 vtable for motionGraph
0000000000000000         *UND*  0000000000000000 operator new(unsigned long)
0000000000000000         *UND*  0000000000000000 motionFactory::motionFactory(double, double, double)

How come objdump sees the constructor and yet g++ doesn't? I know I am making things unnecessarily hard for myself but please I'm lost.


Solution

  • Figured it out. C++ was expecting to see different constructors for different levels of multi inheritance. D didn't provide those since it has no concept of multi inheritance. Which caused the weird errors. Writing a custom link script to rename the calls fixed the problem.