目标:
编译“Acceptor”程序(服务器)。完成后,编译一个“启动器”(客户端),然后打印一个简单的输出,以确认两个应用程序正在相互通信(我已经阅读了 QuickFix 文档并且大部分理解的要求)。
请注意 在发布这个问题之前,已经咨询了 QuickFix 邮件列表和 SO。可以在以下 URL 找到具有类似问题的问题,但是,答案仍然让我有些困惑:
Compiling a quickfix program
问题:
尝试编译以下示例时 承兑人程序完全复制自 http://www.quickfixengine.org/quickfix/doc/html/application.html ,出现了各种错误,如下所示。我使用的编译命令是:
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.h
中定义.编译器识别所有包含的头文件,所以我很困惑为什么它说“应用程序”没有在这个范围内声明。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; }
};
关于c++ - 快速修复 C++ : Errors when compiling Acceptor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63150629/