温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - QuickFix C++: Errors when compiling Acceptor
algorithmic-trading c++ fix-protocol quickfix

其他 - QuickFix C ++:编译受体时出错

发布于 2021-04-13 07:19:52

目标:

编译“ Acceptor”程序(服务器)。完成此操作后,可以编译一个“启动程序”(客户端),然后打印一个简单的输出,以确认两个应用程序正在相互通信(我已阅读QuickFix文档并基本理解了它们的要求)。

请注意,在发布此问题之前,已经咨询了QuickFix邮件列表和SO。在以下URL上可以找到具有类似问题的问题,但是,答案仍然使我有些困惑: 编译quickfix程序

问题:

尝试编译http://www.quickfixengine.org/quickfix/doc/html/application.html精确复制的以下示例Acceptor程序时,出现了各种错误,如下所示。我使用的编译命令是:

g++ trade_server_test.cpp -std=c++11 -fexceptions -finline-functions -lquickfix -lpthread -lxml2

该程序:

#include "quickfix/FileStore.h"
#include "quickfix/FileLog.h"
#include "quickfix/SocketAcceptor.h"
#include "quickfix/Session.h"
#include "quickfix/SessionSettings.h"
#include "quickfix/Application.h"

int main( int argc, char** argv )
{
    try
    {
        if(argc < 2) return 1;
        std::string fileName = argv[1];

        FIX::SessionSettings settings(fileName);

        MyApplication application;
        FIX::FileStoreFactory storeFactory(settings);
        FIX::FileLogFactory logFactory(settings);
        FIX::SocketAcceptor acceptor
          (application, storeFactory, settings, logFactory /*optional*/);
        acceptor.start();
        // while( condition == true ) { do something; }
        acceptor.stop();
        return 0;
    }
    catch(FIX::ConfigError& e)
    {
        std::cout << e.what();
        return 1;
    }
}

错误输出

观察到以下错误:

trade_server_test.cpp: In function ‘int main(int, char**)’:
trade_server_test.cpp:17:3: error: ‘MyApplication’ was not declared in this scope
   MyApplication application;
   ^~~~~~~~~~~~~
trade_server_test.cpp:21:6: error: ‘application’ was not declared in this scope
     (application, storeFactory, settings, logFactory /*optional*/);

然后,我将对象名称从修改"MyApplication""Application",并收到以下错误输出。在头文件中定义了“ Application”类Application.h编译器可以识别所有包含的头文件,因此我对为什么说未在此范围内声明“ Application”感到困惑。

trade_server_test.cpp: In function ‘int main(int, char**)’:
trade_server_test.cpp:17:3: error: ‘Application’ was not declared in this scope
   Application application;
   ^~~~~~~~~~~
trade_server_test.cpp:17:3: note: suggested alternative:
In file included from /usr/local/include/quickfix/Acceptor.h:29:0,
                 from /usr/local/include/quickfix/SocketAcceptor.h:29,
                 from trade_server_test.cpp:3:
/usr/local/include/quickfix/Application.h:43:7: note:   ‘FIX::Application’
 class Application
       ^~~~~~~~~~~
trade_server_test.cpp:21:6: error: ‘application’ was not declared in this scope
     (application, storeFactory, settings, logFactory /*optional*/);
      ^~~~~~~~~~~

再次改变目标"Application",以"FIX::NullApplication"摆脱上述错误,但随后一个新的错误出现的:

/usr/bin/ld: cannot find -lxml2
collect2: error: ld returned 1 exit status

我已成功下载并构建了该程序QuickFix 1.15.1Ubuntu 18.04.2 LTS并能够通过执行以下过程来运行某些示例应用程序,例如OrderMatchTradeClient(尽管仅具有部分功能):

% tar xvzf quickfix-1.15.1.tar.gz
% cd quickfix
% ./bootstrap
% ./configure
% make
% sudo make install

总结性问题

  1. 我怎样才能成功编译样受体上的程序Ubuntu 18.04.2 LTS进行QuickFix 1.15.1对于要链接的库,要用哪些标志编译的头文件等方面的逐步指导,将是高度赞赏的。
  2. 编译命令看起来正确吗?
  3. 是否应将任何头文件与该应用程序一起编译(尽管我认为这些头文件make在该building过程中运行时会被编译

查看更多

提问者
p.luck
被浏览
0
Botje 2020-07-31 16:33

你需要自己提供Application的子类。
让我们看一下Application的声明:

namespace FIX
{
  class Application
  {
  public:
    virtual ~Application() {};
    virtual void onCreate( const SessionID& ) = 0;
    virtual void onLogon( const SessionID& ) = 0;
    virtual void onLogout( const SessionID& ) = 0;
    virtual void toAdmin( Message&, const SessionID& ) = 0;
    virtual void toApp( Message&, const SessionID& )
      throw( DoNotSend ) = 0;
    virtual void fromAdmin( const Message&, const SessionID& )
      throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon ) = 0;
    virtual void fromApp( const Message&, const SessionID& )
      throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType ) = 0;
  };
}

所有标记有这些方法的方法= 0都是纯虚函数:它们没有实现,你不能FIX::Application直接实例化相反,你必须声明一个子类。只要声明在创建实例时在范围内,在哪里执行此操作都无关紧要MyApplication它可以在同一文件中,也可以在你包含的头文件中。

不执行任何操作的Application的简单子类可能如下所示:

class MyApplication : public FIX::Application
{
  void onCreate( const SessionID& ) { std::cout << "onCreate" << std::endl; }
  void onLogon( const SessionID& ) { std::cout << "onLogon" << std::endl; }
  void onLogout( const SessionID& ) { std::cout << "onLogout" << std::endl; }
  void toAdmin( Message&, const SessionID& ) { std::cout << "toAdmin" << std::endl; }
  void toApp( Message&, const SessionID& ) throw( DoNotSend ) { std::cout << "toApp" << std::endl; }
  void fromAdmin( const Message&, const SessionID& ) throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon ) { std::cout << "fromAdmin" << std::endl; }
  void fromApp( const Message&, const SessionID& ) throw( FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType ) { std::cout << "fromApp" << std::endl; }
};