• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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.
0
markvp
Asked:
markvp
  • 2
1 Solution
 
e_tadeuCommented:
Try using g++.exe instead of gcc.exe.
It seems you are using virtual functions, are your headers correctly defined?
0
 
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
      {
      public:
            A(bool b);

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

      class C: public A
      {
      public:
            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).
0
 
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.
0
 
PAQ_ManCommented:
Closed, 125 points refunded.
PAQ_Man
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now