LNK2019 / LNK2001 errors: Why would a library provide a .cpp file with unimplemented functions? (How do they get implemented?)

StackOverflow https://stackoverflow.com/questions/22142359

Question

I think I understand the gist of LNK2019 errors from reading SO and this MSDN article.

I have one Why question and one How question (both asked in the title already).

Why would a library provide a .cpp file with unimplemented functions? I'm guessing the answer is: "So end-users can implement those functions themselves, or 'link' some other thing that does." (Please correct me if I'm wrong, but I'll continue with this assumption.)

For example, in the screenshot below (click for larger version), I show the LNK2019 errors I encountered, as well as the offending file, wx.cpp.

enter image description here

None of the methods in the class mglCanvasWX are implemented (and yes, I've scrolled down :-). Here's a permanent Pastebin of wx.cpp, and here's the output, in case someone wants to peer at the code, but I wouldn't ask of anyone to go so far.

How do such functions get implemented?

I'm guessing it's the .dll files which contain the implementations. Therefore, I need to locate the .dll file implementing Window, ToggleAlpha, ToggleLight, and so on. (I'm guessing I can ignore all the other types of files, .obj, .lib, .exp, etc.) But how do I know where to find those .dll files?—or even know that a .dll file does implement those functions, since they're binary (non-human-readable) files?

I'm sorry to ask two questions at once, but I think these are the essential things I need to understand to resolve this linker error. (I feel I'm missing a single concept, even if I needed to ask in two questions.) Thank you in advance for any guidance you can give, and sorry to add to the existing pile of LNK2019 questions on SO...


Addendum

This might be relevant:

#      define MGL_EXPORT __declspec(dllexport)

But I'm not sure whether this indicates that this unimplemented class is being exported as a DLL (of what use would such a DLL be?), or indicates that this class must be implemented by a DLL file (which would make more sense).

Also, the reason I phrased my question, "Why would a library...", is that the other dependency in this project, mgl-fltk, provides a similar source, but does implement the analogous class and its functions (and builds fine)! See a screenshot here. Its class definition, however, unlike mgl-wx, omits the MGL_EXPORT, hinting to me that FLTK was not intended to be implemented externally.

class mglCanvasFL : public mglCanvasWnd

Theory

Okay, after some more thinking, I came up with a theory, but only an experienced software developer could tell me if it's plausible / makes sense.

Did the developer(s) of MathGL, perhaps, simply not get around to implementing those definitions? That is, is it possible MathGL doesn't yet support wxWidgets?

See, in the original MathGL source, there are these files:

enter image description here

QT, FLTK, and GLUT all implement their mglCanvasQT, mglCanvasFL, and mglCanvasGLUT, e.g.

// qt.cpp

    void mglCanvasQT::Animation()   {   QMGL->animation(true);  }
    void mglCanvasQT::ToggleAlpha() {   QMGL->setAlpha(!QMGL->getAlpha());  }

// fltk.cpp

    void mglCanvasFL::Animation()   {   Fl::lock(); mgl_sshow_cb(0,mgl);    Fl::unlock();   }
    void mglCanvasFL::ToggleAlpha() {   Fl::lock(); mgl->toggle_alpha();    Fl::unlock();   }

// glut.cpp

    class mglCanvasGLUT : public mglCanvasGL
    {
    public:
        // ...
        void ToggleAlpha()  {   _mgl_key_up('r',0,0);   }
        void Animation()    {   _mgl_key_up('m',0,0);   }   ///< Run slideshow (animation) of frames
        // ...
    }

and it's only mglCanvasWX that's left unimplemented, and only mglCanvasWX that has the MGL_EXPORT macro ahead of its class name.

So what's the likely explanation? That WX support just isn't there yet? Or, support for WX exists, but was found easier to provide as an external library (DLL)? I'd really appreciate if an experienced software developer could weigh in on this...

Was it helpful?

Solution

Holy J. Skeet, my theory turned out to be true.

After hours of experimentation (and writing up this question), I began to realize that perhaps wxWidgets simply wasn't implemented for use with MathGL. (See "Theory" edit, above.) I did some Googling under this new context, and voila!—from the maintainer of MathGL himself (whose name I only recognized because it was the User / Group name in the 7-Zip screenshot above)—

MortenMacFly 1/22/11

Hi there, I wonder what the wx sample is doing. It seems there is a stub prepared, but yet no functionality implemented. I'd love to use this library in a wxWidgets project. Any hints?

Alexey Balakin 1/25/11

Hi,

Basically yes. I switched from wxWidgets to Qt many years ago ... So, I'm already forgot many wxWidget percularity and decide to stop making working window based on wxWidget. There are several matters: MathGL already have 2 (based on FLTK and Qt), I have not so much time to write|test wxWidget one :(.

So, right now you can do following:

1) Use MathGL produced RGB bitmap to display image an yours wxWidget control. There is a sample here http://mathgl.sourceforge.net/mathgl_en/mathgl_en_10.html#Drawing-in-memory

2) Use wxMathGL widget defined in mgl/mgl_wx.h . I'm very hope what it should work as is but I didn't test it :(

3) Help me and write|test wxMathGL widget and class mglGraphWX which will display window with controls based on wxWidget.I (and other I think) will be very thankful.

The thread in which I found this discusses some alternatives as well, though I don't know if they work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top