如何编译ACE程序

时间:2019-03-13 12:19:34

标签: c++ sockets networking ace

我第一次使用ACE(自适应通信环境)框架,并且在安装过程中苦苦挣扎。我从here下载了项目文件夹,然后使用了here上的说明。我在/ usr / include /文件夹中包含了'ace'文件夹。然后,我尝试编译该程序:

//client.cpp
#include <ace/Log_Msg.h>
#include <ace/SOCK_Connector.h>
static u_short SERVER_PORT = ACE_DEFAULT_SERVER_PORT;
static const char *const SERVER_HOST = ACE_DEFAULT_SERVER_HOST;
static const int MAX_ITERATIONS = 4;

int
main (int argc, char *argv[])
{
  const char *server_host = argc > 1 ? argv[1] : SERVER_HOST;
  u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : SERVER_PORT;
  int max_iterations = argc > 3 ? ACE_OS::atoi (argv[3]) : MAX_ITERATIONS;
  ACE_SOCK_Stream server;
  ACE_SOCK_Connector connector;
  ACE_INET_Addr addr (server_port,
                      server_host);
  if (connector.connect (server, addr) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open"),
                      -1);
  for (int i = 0; i < max_iterations; i++)
    {
      char buf[BUFSIZ];

      /* Create our message with the message number */
      ACE_OS::sprintf (buf,
                       "message = %d\n",
                       i + 1);

      if (server.send_n (buf,
                         ACE_OS::strlen (buf)) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n",
                           "send"),
                          -1);
      else
        /* Pause for a second.  */
        ACE_OS::sleep (1);
    }

  if (server.close () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "close"),
                      -1);
  return 0;
}

g++ client.cpp一起使用后,出现以下错误:

/tmp/ccsSpahN.o: In function `main':
client.cpp:(.text+0xe3): undefined reference to `ACE_INET_Addr::ACE_INET_Addr(unsigned short, char const*, int)'
client.cpp:(.text+0x10f): undefined reference to `ACE_Addr::sap_any'
client.cpp:(.text+0x11c): undefined reference to `ACE_SOCK_Connector::connect(ACE_SOCK_Stream&, ACE_Addr const&, ACE_Time_Value const*, ACE_Addr const&, int, int, int, int)'
client.cpp:(.text+0x12f): undefined reference to `ACE_Log_Msg::last_error_adapter()'
client.cpp:(.text+0x13a): undefined reference to `ACE_Log_Msg::instance()'
client.cpp:(.text+0x16a): undefined reference to `ACE_Log_Msg::conditional_set(char const*, int, int, int)'
client.cpp:(.text+0x191): undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char const*, ...)'
client.cpp:(.text+0x1db): undefined reference to `ACE_OS::sprintf(char*, char const*, ...)'
client.cpp:(.text+0x21e): undefined reference to `ACE_Log_Msg::last_error_adapter()'
client.cpp:(.text+0x229): undefined reference to `ACE_Log_Msg::instance()'
client.cpp:(.text+0x259): undefined reference to `ACE_Log_Msg::conditional_set(char const*, int, int, int)'
client.cpp:(.text+0x280): undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char const*, ...)'
client.cpp:(.text+0x2af): undefined reference to `ACE_SOCK_Stream::close()'
client.cpp:(.text+0x2be): undefined reference to `ACE_Log_Msg::last_error_adapter()'
client.cpp:(.text+0x2c9): undefined reference to `ACE_Log_Msg::instance()'
client.cpp:(.text+0x2f9): undefined reference to `ACE_Log_Msg::conditional_set(char const*, int, int, int)'
client.cpp:(.text+0x320): undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char const*, ...)'
client.cpp:(.text+0x33b): undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
client.cpp:(.text+0x37e): undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
/tmp/ccsSpahN.o: In function `ACE::send_n(int, void const*, unsigned long, ACE_Time_Value const*, unsigned long*)':
client.cpp:(.text._ZN3ACE6send_nEiPKvmPK14ACE_Time_ValuePm[_ZN3ACE6send_nEiPKvmPK14ACE_Time_ValuePm]+0x34): undefined reference to `ACE::send_n_i(int, void const*, unsigned long, unsigned long*)'
client.cpp:(.text._ZN3ACE6send_nEiPKvmPK14ACE_Time_ValuePm[_ZN3ACE6send_nEiPKvmPK14ACE_Time_ValuePm]+0x53): undefined reference to `ACE::send_n_i(int, void const*, unsigned long, ACE_Time_Value const*, unsigned long*)'
/tmp/ccsSpahN.o: In function `ACE_SOCK_IO::ACE_SOCK_IO()':
client.cpp:(.text._ZN11ACE_SOCK_IOC2Ev[_ZN11ACE_SOCK_IOC5Ev]+0x14): undefined reference to `ACE_SOCK::ACE_SOCK()'
collect2: error: ld returned 1 exit status

所以我的问题是:

  1. 为什么会出现此错误。我想走哪一步?
  2. 编译时需要链接哪个库?请提供语法。

编辑:在评论部分中,我正在编辑此问题。看到错误后,很明显该错误是由于在使用g ++进行编译时未链接到某个库而引起的。我在第二个问题中明确指出了这一点。我想知道在编译过程中需要添加的-l(某些库)选项是什么。

0 个答案:

没有答案