I am using ACE (adaptive communication environment) framework for the first time and am struggling a lot in installation process. I downloaded the project folder from here and then used the instructions written here. I included the 'ace' folder in /usr/include/ folder. Then I tried to compile this program:
//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;
}
After compiling with the command g++ client.cpp
, I got the following errors:
/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
So my question is:
- Why is this error coming.Which step am I missing?
- What library do I need to link while compilation? Please provide syntax.
EDIT: In reference to the comment section I am editing this question. Seeing the errors, it is clear that the error is because of a library which has not been linked during compilation with g++. I clearly specified that in my second question. I want to know what will be that -l(some library) option that needs to be added during compilation.