编译“ 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.1
,Ubuntu 18.04.2 LTS
并能够通过执行以下过程来运行某些示例应用程序,例如OrderMatch
和TradeClient
(尽管仅具有部分功能):
% tar xvzf quickfix-1.15.1.tar.gz
% cd quickfix
% ./bootstrap
% ./configure
% make
% sudo make install
Ubuntu 18.04.2 LTS
进行QuickFix 1.15.1
?对于要链接的库,要用哪些标志编译的头文件等方面的逐步指导,将是高度赞赏的。make
在该building
过程中运行时会被编译?你需要自己提供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; }
};
我真的很感谢详细的答案,这已经完全解决了我的问题。感谢您抽出宝贵的时间来提供这样一个结构合理的解释-现在一切都按预期进行了。