PDA

View Full Version : MS Visual C++ Linker warnings



YuriyRusinov
4th December 2007, 18:07
Hello, All !

I develop class library for linux and windows. Here is headers files
searchengine.h


#ifdef WIN32
#define SEARCH_EXPORT __declspec(dllexport)
#else
#define SEARCH_EXPORT
#endif

class SearchForm;

class SEARCH_EXPORT SearchEngine : public QObject
{
public:
SearchEngine (QObject *parent=0);
...
static SearchEngine* GUISetParams (QWidget *parent=0, Qt::WFlags f=0);
...
private:
SearchForm *sForm;
...
private:
Q_OBJECT
};

searchform.h



class SearchEngine;

class SearchForm : public QDialog
{
public:
SearchForm (SearchEngine *se, QWidget *parent=0, Qt::WFlags f=0);
...
private:
SearchEngine *sEngine;
...
private:
Q_OBJECT
};

Sources files are
searchengine.cpp


#include "searchengine.h"
#include "searchform.h"

SEARCH_EXPORT SearchEngine * SearchEngine::self=0;

SearchEngine::SearchEngine (QObject *parent)
: QObject (parent)
{
};
...
SearchEngine* SearchEngine::GUISetParams (QWidget *parent, Qt::WFlags f)
{
SearchEngine *se = new SearchEngine ();
se->sForm = new SearchForm (se);
se->sForm->show ();
return se;
}

searchform.cpp


SearchForm (SearchEngine *se, QWidget *parent, Qt::WFlags f) :
QDialog (parent,f ),
sEngine (se)
{
...
}
...

When I try to build project under Linux, all works fine, but if I try to do it under Windows, I receive some linkage warnings such this


searchform.obj : warning LNK4217: locally defined symbol ?setTimeRange@SearchEngine@@QAEXABVQDateTime@@0@Z (public: void __thiscall SearchEngine::setTimeRange(class QDateTime const &,class QDateTime const &)) imported in function "private: void __thiscall SearchForm::Search(void)" (?Search@SearchForm@@AAEXXZ)
...

function SearchEngine::setTimeRange (const QDateTime&, const QDateTime&) and others are defined in searchengine.cpp. Where is the troubles and which way I have to solve this problem ?

Thanks in advance.

marcel
4th December 2007, 18:20
It is as simple as this:http://msdn2.microsoft.com/en-us/library/aa3se25k(vs.71).aspx

YuriyRusinov
4th December 2007, 18:27
I try to do this, but nothing changes, when I try to


#define SEARCH_EXPORT

I receive the same warnings.

ChristianEhrlicher
5th December 2007, 06:51
Maybe SearchEngine::setTimeRange() is inlined in your project - but to few code ...

YuriyRusinov
5th December 2007, 07:55
No, this warnings are related to all functions of class SearchEngine, both inlined and calls.

jpn
5th December 2007, 07:59
Is the problem about building the library which contains SearchEngine or a project which links to that library? It's just that the export macro definition looks insufficient to me. You should export when building the lib and import when using the lib. Try searching the forums for "Q_DECL_EXPORT" and "Q_DECL_IMPORT".

ChristianEhrlicher
5th December 2007, 08:03
This means that you link both, searchengine.cpp and searchform.cpp into one library/application. If this is the case there's no need for the import/export macros - just remove them.

YuriyRusinov
5th December 2007, 08:33
I try to remove all these macro and receive the same warnings and 4 unresolved externals, search error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall SearchEngine::setTimeRange(class QDateTime const &,class QDateTime const &)" (__imp_?setTimeRange@SearchEngine@@QAEXABVQDateTim e@@0@Z) referenced in function "private: void __thiscall SearchForm::Search(void)" (?Search@SearchForm@@AAEXXZ). SearchForm
has to be member of class SearchEngine and has to contains pointer onto SearchEngine object, if I build library without GUI therefore without any graphical forms, all built ok.

ChristianEhrlicher
5th December 2007, 08:39
You really should read what I write

either you build a lib where searchengine.cpp is and leave the export macro like it is [b] or you don't build a lib, put searchengine.cpp into your app and remove the macro. What you currently do is that you have the export macro but also link searchengine.cpp to your app. Look into your pro-File (or whatever buildsystem you use) and you'll see!

YuriyRusinov
6th December 2007, 08:07
OK, thanks, I try to research this on examples, because this problem does not arise before despite of linkage with other libraries take place.