1

I have an application that was built without problems in Linux, now I'm trying to compile it against Windows, I created a .pro file specially for compiling it in windows.

I use a pseudo-class ( just a namespace with a buch of methods, but without a class statement so I can use it without creating an object ) that's working just fine in Linux, but when I try to compile against windows I get an 'unresolved external symbol' throughout all the code where this pseudo-class's being used.

The pseudo-class goes like this:

namespace foo {
   bool method_bar();
}

Then I use it like this:

foo:method_bar(); 

Pretty straight-forward, somewhat like static methods.

Before somebody asks me, why not use static methods in first place; I have some special situations in which I cannot use these methods as static. That's why I buit the methods directly under the namespace.

So, at my .PRO file, I added the .h and .cpp files from my pseudo-class like this:

 HEADERS += \
       ....
       include/foo.h
       ....


    SOURCES += \
       ....
       include/foo.cpp
       ----

Although it includes the files in my projects, it's throwing that LNK2019: unresolved external symbol error.

I'm no beginner with programming, but I'm a beginner with Qt.

Any help will be deeply appreciated.

ps: forgive my English mistakes.

  • Do you have `foo.obj` together with other object files? Does it contain the symbol for `bool foo::method_bar()` ? Check with DUMPBIN. – Pavel Zdenek Oct 16 '12 at 16:45
  • I don't have a foo.obj. Just consume straight foo::method_bar(). – Former User of Mine Mar 01 '13 at 19:33
  • If your declaration `bool method_bar();` in `foo.h` actually have some implementation body in `foo.cpp` (it would be useless without a body, right?), then you of course need to have `foo.obj`, where this body is compiled. It's nice that you "consume the header", but compiler needs the body. And that's what LNK2019 means. – Pavel Zdenek Mar 01 '13 at 21:19

1 Answers1

0

first of all the scope operator is foo"::"method_bar();

See that the header is included before the usage of the function so that the places where ever you are calling this function knows about the declarations of the function

There is no problem in using namespace in QT.

One more suggestion would be

using namespace foo;

Looking at the complete code would really help me in resolving the problem

Srikan
  • 2,161
  • 5
  • 21
  • 36
  • Sorry for taking to long to get back, I totally forgot about this post. I had forgotten to add the 'using namespace foo', which was the cause of the trouble. – Former User of Mine Mar 01 '13 at 19:34