使用gcc为Windows编译DLL

时间:2017-03-06 10:27:56

标签: c++ gcc dll

我想用gcc从IModel.h编译一个dll。 IModel.h文件的代码:

#ifndef IModel_DLL_H
#define IModel_DLL_H


extern "C" 
{
  #ifdef SMPInfrastructureDemoCPP3_DLL_EXPORTS
    #define SMPInfrastructureDemoCPP3_API __declspec(dllexport)
  #else
    #define SMPInfrastructureDemoCPP3_API __declspec(dllimport)
  #endif 

  namespace InfrastructureSMPCPP
  { 
    enum ModelStateKind
    {
        MSK_Created,
        MSK_Publication,
        MSK_Configuration,
        MSK_Connected
    };
    class ILogger
    {
        public:
           ILogger ()
           {

           }

};
class ISimulator
{

};
class IPublication
{
};
class IModel
{
    public:
        IModel ();
        SMPInfrastructureDemoCPP3_API void Configure(ILogger Log);
        SMPInfrastructureDemoCPP3_API void Connect(ISimulator simulator);
        SMPInfrastructureDemoCPP3_API ModelStateKind GetState();
        SMPInfrastructureDemoCPP3_API void Publish(IPublication receiver);
         ILogger Log;
};
}
}
#endif

编译这个我用命令

使用gcc
g++ -c -DSMPInfrastructureDemoCPP3_DLL_EXPORTS IModel.cpp
g++ -shared -o IModel.dll IModel.o -Wl,--out-implib,libexample_dll.a

与此参考文献http://www.mingw.org/wiki/sampledll

类似

在第一个comman之后我创建了一个IModel.o文件。好。

但我无法执行第二个命令,因为此错误

g++ : unrecognized option '-shared'

我做错了什么?

0 个答案:

没有答案