Error: function definition is marked dllimport

半腔热情 提交于 2019-12-22 11:27:33

问题


I'm attempting to get a toy program running with AVT's VIMBA SDK. At the moment, it is going well save for one caveat. When I attempt to compile, I get a series of errors (14 of them) that all are marked same thing:

function *insert call here* definition is marked dllimport

The file itself is below- the curious thing is that in in this file, only ~IFeatureObserver(), IFeatureObserver(), and IFeatureObserver( const IFeatureObserver& ) are triggering the error; FeatureChanged() does not error out during a compile.

#ifndef AVT_VMBAPI_IFEATUREOBSERVER_H
#define AVT_VMBAPI_IFEATUREOBSERVER_H

#include <VimbaCPP/Include/VimbaCPPCommon.h>
#include <VimbaCPP/Include/SharedPointerDefines.h>
#include <VimbaCPP/Include/Feature.h>
#include <vector>

namespace AVT {
namespace VmbAPI {

class IFeatureObserver 
{
  public:

    IMEXPORT virtual void FeatureChanged( const FeaturePtr &pFeature ) = 0;

    IMEXPORT virtual ~IFeatureObserver() {}

  protected:
    IMEXPORT IFeatureObserver() {}
    IMEXPORT IFeatureObserver( const IFeatureObserver& ) { /* No copy ctor */ }
};
typedef std::vector<IFeatureObserverPtr> IFeatureObserverPtrVector;

}} // namespace AVT::VmbAPI

#endif

After tracking down source of IMEXPORT, I found it in a .h file.

#if defined (_WIN32)
    #if defined AVT_VMBAPI_CPP_EXPORTS          // DLL exports
        #define IMEXPORT __declspec(dllexport)
    #elif defined AVT_VMBAPI_CPP_LIB            // static LIB
        #define IMEXPORT
    #else                                       // import
        #define IMEXPORT __declspec(dllimport)
    #endif
#elif defined (__GNUC__) && (__GNUC__ >= 4) && defined (__ELF__)
    #define IMEXPORT
#elif defined (__APPLE__)
    #define IMEXPORT
#else
    #error Unknown platform, file needs adaption
#endif

I am currently programming in Qt on a Win7-32 bit machine, and as far as I can tell IMEXPORT is being defined as __declspec(dllimport).

Thoughts? Thanks in advance!


回答1:


You should define the macro AVT_VMBAPI_CPP_EXPORTS in your makefile or VS project. This way IMEXPORT is defined as dllexport for this library and dll import when other libraries/app use it.

BTW it's cleaner to add this attribute to the class itself, not every function.

class IMEXPORT IFeatureObserver {
public:
    virtual void FeatureChanged( const FeaturePtr &pFeature ) = 0;
};


来源:https://stackoverflow.com/questions/20644151/error-function-definition-is-marked-dllimport

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!