[Libwebsockets] Integrate new file into libwebsocket make build system

Hemant Kumar hkumar at arubanetworks.com
Sat Nov 23 00:49:36 CET 2013


Hi Edwin/Andy

Thanks!! You are right, I missed including -lwebsockets.
That solved some of my problem but not all of it:

I need to access the socket file descriptor, which is defined as sock variable in wsi.
So, I use the following :

 void socket_send(struct libwebsocket* client_socket)
 73 {
 74     int new_fd = client_socket->sock;


If I dont include private-libwebsockets.h , then it ends up in following error:
bash-4.1$ gcc  -Wall  -I/home/hkumar/libwebsockets/lib/  -L/home/hkumar/libwebsockets/build/lib/  tcp_nb_client.c tcp_nb_send.c  -lrt  -lwebsockets -o trafficclient
tcp_nb_send.c: In function ‘socket_send’:
tcp_nb_send.c:74: error: dereferencing pointer to incomplete type


And if I include the file , then it results in following:

bash-4.1$ gcc  -Wall  -I/home/hkumar/libwebsockets/lib/  -L/home/hkumar/libwebsockets/build/lib/  tcp_nb_client.c tcp_nb_send.c  -lrt  -lwebsockets -o trafficclient
In file included from tcp_nb_send.c:13:
../lib/private-libwebsockets.h:29:20: error: config.h: No such file or directory
tcp_nb_send.c: In function ‘socket_send’:
tcp_nb_send.c:139: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘__time_t’


I am kind of stuck at this point, will appreciate any suggestion to overcome this.
Thanks for your time.

Regards
Hemant


________________________________
From: Andy Green [extracats at googlemail.com] on behalf of Edwin van den Oetelaar [andy.green at linaro.org]
Sent: Friday, November 22, 2013 3:44 PM
To: Hemant Kumar
Cc: libwebsockets at ml.libwebsockets.org
Subject: Re: [Libwebsockets] Integrate new file into libwebsocket make build system


The undefined references happen when you do not link to the library.
Add the libwebsockets library and the errors will go away.

gcc  -Wall  -I/home/hkumar/libwebsockets/lib/ -L/home/hkumar/libwebsockets/build/lib/  traffic_client.c traffic_client_send.c  -lrt -lwebsockets -o trafficclient

Greetings and good luck,
Edwin van den Oetelaar

On Sat, Nov 23, 2013 at 12:25 AM, Hemant Kumar <andy.green at linaro.org<mailto:andy.green at linaro.org>> wrote:
Hi Edwin

Thanks for your reply.
As you mentioned, I first compiled my library and have .so files under libwebsocket/lib . Next , I created a new file under test-server directory and included libwebsockets.h .
On compilation , it throws following errors:

bash-4.1$ gcc  -Wall  -I/home/hkumar/libwebsockets/lib/ -L/home/hkumar/libwebsockets/build/lib/  tcp_nb_client.c tcp_nb_send.c  -lrt  -o trafficclient
/tmp/ccCmQqeF.o: In function `main':
tcp_nb_client.c:(.text+0x1cd): undefined reference to `libwebsocket_create_context'
tcp_nb_client.c:(.text+0x256): undefined reference to `libwebsocket_client_connect'
tcp_nb_client.c:(.text+0x2bd): undefined reference to `libwebsocket_context_destroy'
/tmp/ccMg2kKl.o: In function `socket_send':
tcp_nb_send.c:(.text+0x261): undefined reference to `libwebsocket_write'
collect2: ld returned 1 exit status
I am at loss to understand what’s wrong in the above process ? Please suggest.
Right now , I am not accessing sock variable defined inside struct libwebsocket structure, for which I needed to include private-libwebsocket include file also.

Thanks
Hemant

From: Andy Green [mailto:extracats at googlemail.com<mailto:extracats at googlemail.com>] On Behalf Of Edwin van den Oetelaar
Sent: Friday, November 22, 2013 3:15 PM
To: Hemant Kumar
Cc: libwebsockets at ml.libwebsockets.org<mailto:libwebsockets at ml.libwebsockets.org>
Subject: Re: [Libwebsockets] Integrate new file into libwebsocket make build system

Hello Hemant,

The usual procedure is to build and install the library and use it as such.
You would make a new project and
#include <libwebsockets.h>

and then link to the library to build the final binary. (using -l flag)
gcc myapp.c -o myapp -lwebsockets

Working inside the library directory is not the normal way.

Greetings,
Edwin van den Oetelaar

On Fri, Nov 22, 2013 at 11:54 PM, Hemant Kumar <andy.green at linaro.org<mailto:andy.green at linaro.org>> wrote:
Hi

I am trying to add a new source file into libwebsocket build system.

I am using libwebsocket_write() and  related APIs mentioned in libwebsocket.c  in my source code and have included the following files. Also, I am trying to reference the sock variable defines inside struct libwebsocket , which is in turn is defined in private-libwebsocket.h  .

#include "../lib/private-libwebsockets.h"
#include <libwebsockets.h>

My source file is placed under test-server directory , I end up with following error when I use gcc separately to compile the file:

gcc  -Wall  -I/home/hkumar/libwebsockets/lib/ -L/home/hkumar/libwebsockets/build/lib/  traffic_client.c traffic_client_send.c  -lrt  -o trafficclient

In file included from traffic_client.c:18:
../lib/private-libwebsockets.h:29:20: error: config.h: No such file or directory
In file included from traffic_client_send.c:13:
../lib/private-libwebsockets.h:29:20: error: config.h: No such file or directory

I do not see any config.h in lib directory which means that it might be taken care by libwebsocket cmake build utility.
Can you please suggest, how I can add my new source file and compile it successfully?

Thanks
Hemant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20131122/7e55d762/attachment-0001.html>


More information about the Libwebsockets mailing list