[Libwebsockets] libwebsockets from C++

"Andy Green (林安廸)" andy at warmcat.com
Fri Feb 1 18:21:57 CET 2013


On 02/02/13 00:25, the mail apparently from Drew Noakes included:
> Hi Andy,
>
> Thank you for the detailed response. In the end it was the missing -l
> argument that was tripping me up and causing the linker to miss the
> library. Things seem to be working well.
>
> I would like to compile libwebsockets into my application if possible,
> rather than requiring it to be installed on the target OS. It's my
> understanding that the above links to the .so file. Is there a simple
> change I can make to achieve this?

This is just a general question about static linking... you just include 
the path (eg, usually /usr/lib or /usr/lib64) to the .a on the g++ line 
instead.

I'm not sure what it buys you though since other things in the rootfs 
will be using shared libs, and libwebsockets wants zlib in its default 
config as well.

Also notice that the LGPL cares about static linking if you distribute 
the result

http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License#Differences_from_the_GPL
http://www.gnu.org/copyleft/lesser.html#section4

Life will be simpler if you dynamically link I think... you'll probably 
have more than one file anyway what with the html, images etc.

-Andy

> On 1 February 2013 00:33, "Andy Green (林安廸)" <andy at warmcat.com
> <mailto:andy at warmcat.com>> wrote:
>
>     On 01/02/13 01:50, the mail apparently from Drew Noakes included:
>
>     (looping the libwebsockets mailing list)
>
>
>         Thanks for your work on libwebsockets. It looks like a very well put
>         together open source project and it's great to see such activity
>         on it
>         over the week or so that I've been looking at it.
>
>         It's been a long time since I've done any C, and my C++ is
>         passable but
>         not great (I'm much stronger in managed languages like Java/C#,
>         and my
>         native skills have atrophied). I'm having trouble building a
>         test server
>         using g++ and I'm sure it's something really obvious.
>
>         I've created a new repo and added 'libwebsockets' as a
>         submodule. In my
>         root I have a modified version of test-server.c that I've started to
>         convert into C++ as a first step towards integrating it into my
>         application (which runs on a small humanoid robot as part of a
>         university RoboCup team.) I'd like to stream real-time telemetry
>         to a
>         browser app using your library.
>
>         I run a few open source projects myself and know that it's hard
>         to field
>         questions from people without much experience, so rather than
>         ask about
>         my specific compiler problems (undefined references), I wonder
>         if you
>         would be able to put together some sample code that demonstrated an
>         advisable way of creating a libwebsockets-based service within a C++
>         application, as well as perhaps a simple makefile.
>
>         Selfishly, I am not interested in daemonising, SSL or client code.
>         Others may be.
>
>         Thanks again for your efforts on this open source project.
>
>
>     The reason there's no g++ specific sample is it's not any big deal.
>
>     To reproduce a workable result, copy the test-server.c somewhere.
>
>     C++ has slightly different rules, void * is not magic casting glue
>     any more, so you need this cosmetic patch to get rid of casting
>     complaints
>
>     --- a/test-server.c     2013-01-31 09:39:09.794712848 +0800
>     +++ b/test.cpp  2013-02-01 08:25:27.533450384 +0800
>     @@ -107,7 +107,7 @@
>              case LWS_CALLBACK_HTTP:
>
>                      for (n = 0; n < (sizeof(whitelist) /
>     sizeof(whitelist[0]) - 1); n++)
>     -                       if (in && strcmp(in, whitelist[n].urlpath) == 0)
>     +                       if (in && strcmp((const char *)in,
>     whitelist[n].urlpath) == 0)
>                                      break;
>
>                      sprintf(buf, LOCAL_RESOURCE_PATH"%s",
>     whitelist[n].urlpath);
>     @@ -260,7 +260,7 @@
>              unsigned char buf[LWS_SEND_BUFFER_PRE___PADDING + 512 +
>
>     LWS_SEND_BUFFER_POST_PADDING];
>              unsigned char *p = &buf[LWS_SEND_BUFFER_PRE___PADDING];
>     -       struct per_session_data__dumb___increment *pss = user;
>     +       struct per_session_data__dumb___increment *pss = (struct
>     per_session_data__dumb___increment *)user;
>
>              switch (reason) {
>
>     @@ -288,7 +288,7 @@
>       //             fprintf(stderr, "rx %d\n", (int)len);
>                      if (len < 6)
>                              break;
>     -               if (strcmp(in, "reset\n") == 0)
>     +               if (strcmp((const char *)in, "reset\n") == 0)
>                              pss->number = 0;
>                      break;
>              /*
>     @@ -337,7 +337,7 @@
>                                                     void *user, void
>     *in, size_t len)
>       {
>              int n;
>     -       struct per_session_data__lws_mirror *pss = user;
>     +       struct per_session_data__lws_mirror *pss = (struct
>     per_session_data__lws_mirror *)user;
>
>              switch (reason) {
>
>
>     Afterwards, you can build it as "cpptest" just like this
>
>     g++ -DINSTALL_DATADIR=\"/usr/__share\" -ocpptest test.cpp -lwebsockets
>
>     You only need to care about INSTALL_DATADIR because the test-server
>     wants it, if your version based on that doesn't care you won't need
>     to define it either.
>
>     -Andy
>
>




More information about the Libwebsockets mailing list