Linking libraries with gcc on Windows

I have the following situation with mingw gcc 3.4.4 on Windows 2000: static libraries a.lib and b.lib; b.lib uses class C defined in a.lib. application links to a.lib and b.lib (with command -la -lb). The linker gives an error saying "undefined reference to `vtable for C'". If I make b.lib use another class from a.lib, I get an extra similar error for that class.

What am I doing wrong? I tried to add the command -la when building b.lib, but that doesn't change anything (I think it is useless).

The same libraries and application work just fine with Visual Studio.
Who is Participating?
PAQ_ManConnect With a Mentor Commented:
Closed, 125 points refunded.
Community Support Moderator
Try using g++.exe instead of gcc.exe.
It seems you are using virtual functions, are your headers correctly defined?
markvpAuthor Commented:
When I said gcc, I actually meant the collection of compilers that includes g++. I do use g++. I'm sure my headers are defined correctly. The class looks like this:

namespace MyNamespace
      class A
            A(bool b);

            virtual const String& GetType() const = 0;
            virtual String GetInfo() const = 0;

      class C: public A
            C(): A(true) {}

            virtual const String& GetType() const;
            virtual String GetInfo() const;

The implementation in the cpp-file looks correct (and works perfectly in Visual Studio).

A static instance of C is created in a cpp-file in b.lib. Removing that instance solves the problem, which proves that the problem is in there (but of course I need that instance).
markvpAuthor Commented:
I found the problem. It is the order that the libraries are specified. So if it is -lb -la instead of -la -lb, it works fine.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.