Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone!

I have a problem with an old project, that they want me to compile in Visual Studio. This application was working in QtCreator with gcc compiler, but while in VS10 with Qt implementation it has some compile errors. The linker doesn't find the methods in the dll. This is a sample from the problematic classes:

C++
template <class SW> //SettingsWidget
class RCC_EXPORT_IMPORT SettingsWidgetList : public ObjectList<SW>
{
    public:
        inline RCC::Result apply()
        {
            bool isOk=true;
            for(int i=0, l=ObjectList<SW>::count(); i < l; ++i)
            {
                if(!rcc_resultToBool((*this)[i]->apply()))
                    isOk=false;
            }
            return rcc_boolToResult(isOk);
        }
};



This is from the dll's public header.
...and the linker tells this:

Error   794 error LNK2019: unresolved external symbol "__declspec(dllimport) public: enum ReworkClient::RCC::Result __thiscall ReworkClient::SettingsWidgetList<class ReworkClient::ProfileSettingsWidget>::apply(void)" (__imp_?apply@?$SettingsWidgetList@VProfileSettingsWidget@ReworkClient@@@ReworkClient@@QAE?AW4Result@RCC@2@XZ) referenced in function "private: void __thiscall ProfileDialog::on_OkButton_clicked(void)" (?on_OkButton_clicked@ProfileDialog@@AAEXXZ) C:\!projects\c++\ReworkClient\2.0.x\ReworkClient\rcprofile.obj  ReworkClient

It seems the problem with the apply() method, but I don't understand what can be the difference between the VS and gcc compilers working. Anyone has any idea what can be wrong with the apply method's declaration?
Any idea are welcomed (even critiques)! Im out of clues...

Thank you for reading!
Regards
Adam
Posted
Updated 7-Feb-14 23:53pm
v2

Your SettingsWidgetList class is a template class and hence the compiler generates code for it at the moment you instanciate an object of it with a concrete template parameter. When you compiled your DLL, there probably was no need to instantiate any such object in your library code. And hence the compiler did not produce the member functions in your DLL.

In your client code, however, you instantiate an object of type SettingsWidgetList<profilesettingswidget></profilesettingswidget>, something the compiler has not seen, when you created the DLL. Hence it cannot find the apply method in the DLL.

If ProfileSettingsWidget is the only template parameter that you intend to use for the SettingsWidgetList class, you can force the compiler to generate the required code by
instantiating an object of type SettingsWidgetList<profilesettingswidget></profilesettingswidget> in your DLL code.

In general, however, the concepts of DLLs and template classes are somewhat excluding each other. A template class is usually distributed just by the header file that defines it and not via precompiled code of a DLL.
 
Share this answer
 
Comments
CzimerA 8-Feb-14 6:47am    
Yes normally it seems the header file should be enough, because of the inline declaration, I wonder why the client side trying to pull out from the dll. Unfortunately ProfileSettingsWidget is not the only class that uses this class, but I will try the instantiation. Thanks!
nv3 8-Feb-14 7:52am    
It's probably the RCC_EXPORT_IMPORT declaration of your class that tells the compiler to look for the apply function in the DLL. If you ramove that everything should also work fine.
CzimerA 8-Feb-14 8:01am    
I tried that before, somehow the compiler starts to argue against the "apply" of the iterator. It cannot find it! Is it possible that, the compiler ignores the 'apply' method of the SettingsWidgetList, if the class is exported?
nv3 8-Feb-14 8:35am    
I wouldn't think so. Which error message do you get when you remove the RCC_EXPORT_IMPORT from the class declaration?
CzimerA 8-Feb-14 8:50am    
"left of '->apply' must point to class/struct/union/generic type" this belongs to the iterator,
but the most weird is this:
"use of undefined type 'ReworkClient::BarcodeValidator'" this error may belongs to SettingsWidgetForObject class, that is used by the MOC from UI file.
I suspect it may be that the DLL's exports are standard C style, but the code you are generating is C++. You need to use the following construct around the QT headers.
C++
extern "C"{
// QT includes go here
}

See http://msdn.microsoft.com/en-us/library/0603949d.aspx[^] for a full description.
 
Share this answer
 
Comments
CzimerA 8-Feb-14 6:35am    
Unfortunately it does not seem to be working. I got much more errors than before. Anyway I dont think templates are working in C style.
CzimerA 8-Feb-14 6:35am    
...but good point anyway! Thank thee :)
Richard MacCutchan 8-Feb-14 6:43am    
Did you rebuild the DLL with the Microsoft compiler and linker?
CzimerA 8-Feb-14 7:09am    
Yes but it still not working, I got some compile errors from QT includes.
Richard MacCutchan 8-Feb-14 7:12am    
Well I'm sorry, but no one here can guess what those errors could be.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900