[Libwebsockets] [libwebsockets] Cross compiling issue (#32)

"Andy Green (林安廸)" andy at warmcat.com
Sun Nov 24 07:39:03 CET 2013


On 13/11/13 23:18, the mail apparently from l46kok included:
> I'm currently trying to cross compile libwebsockets on ubuntu using this
> toolchain.
>
> http://wiki.blueocty.com/index.php?title=GNU_Toolchain
>
> I've verifed that the toolchain works as I've compiled a sample binary
> for ARM.
>
> As shown in README.build of libwebsockets, I've edited my
> cross-arm-linux-gnueabihf.cmake to the newly downloaded toolchain then
> ran CMake against it.
>
> CMake runs successfully, although there's two things that concerns me.
>
> |-- The C compiler identification is GNU 4.3.2
> -- The CXX compiler identification is GNU 4.3.2
> -- Check for working C compiler: /usr/arm-2008q3/bin/arm-none-linux-gnueabi-gcc
> -- Check for working C compiler: /usr/arm-2008q3/bin/arm-none-linux-gnueabi-gcc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: /usr/arm-2008q3/bin/arm-none-linux-gnueabi-g++
> -- Check for working CXX compiler: /usr/arm-2008q3/bin/arm-none-linux-gnueabi-g++ -- wor
> ks
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- CMAKE_TOOLCHAIN_FILE='/home/l46kok/Desktop/libwebsockets-1.23-chrome32-firefox24/cros
> s-arm-linux-gnueabihf.cmake'
> ...
> -- Looking for unistd.h
> -- Looking for unistd.h - found
> -- Looking for vfork.h
> -- Looking for vfork.h - not found
> -- Looking for zlib.h
> -- Looking for zlib.h - not found
> |
>
> I was under the impression that libwebsockets required zlib, but cmake
> finishes successfully for some reason.

Depends on the other options... it's used in an extension.

> Anyhow, now I try to do make. Immediately, I get an error.

Well, not immediately, but ok -->

> |Scanning dependencies of target websockets
> [  3%] Building C object CMakeFiles/websockets.dir/lib/base64-decode.c.o
> [  6%] Building C object CMakeFiles/websockets.dir/lib/handshake.c.o
> [ 10%] Building C object CMakeFiles/websockets.dir/lib/libwebsockets.c.o
> [ 13%] Building C object CMakeFiles/websockets.dir/lib/output.c.o
> cc1: warnings being treated as errors
> /home/l46kok/Desktop/libwebsockets-1.23-chrome32-firefox24/lib/output.c: In function 'lws_issue_raw':
> /home/l46kok/Desktop/libwebsockets-1.23-chrome32-firefox24/lib/output.c:162: error: label 'handle_truncated_send' defined but not used
> make[2]: *** [CMakeFiles/websockets.dir/lib/output.c.o] Error 1
> make[1]: *** [CMakeFiles/websockets.dir/all] Error 2
> make: *** [all] Error 2

Sorry this is a bug, it's fixed here

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=944a78dc58fc30730de9635a9fb865d474487845

> It's strange, because I didn't get such label defined but not used
> errors when I compiled regularly instead of cross compiling. Anyhow, I

It's only coming because of LWS_NO_EXTENSIONS option, not because of 
cross itself.

> turned off the -werror flag to stop warnings from halting my
> compilation, then tried make && make install, and the process
> successfully finishes (with the above error displayed as warning).
>
> I've also verified that the library is compiled in ARM architecture.
>
> |root at ubuntu:/home/l46kok/Desktop/libwebsockets-1.23-chrome32-firefox24/build# file /usr/lib/libwebsockets.so.4.0.0
> /usr/lib/libwebsockets.so.4.0.0: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
> |

Yes I made that cross CMake config a while back and confirmed this much. 
  The library and test apps ran on both ARM and MIPS.

> Then finally, I try to compile a very simple example code. For some
> reason, the compiler isn't able to find the header file to the library.
>
> |root at ubuntu:/home/l46kok/Desktop/websocketserver# arm-linux-gcc test.c -lwebsockets -o test
> test.c:4:27: error: libwebsockets.h: No such file or directory

You need to take care with cross ^^

Outside of the headers that came with your toolchain, everything else is 
expected to be coming out of some cross "chroot" type dir somewhere. 
Usually it's in the directory structure of your cross toolchain somewhere.

It'd be very wrong if your cross toolchain started trying to use 
includes or libraries found in the usual places in your build host. 
They may be utterly different versions or arches or whatever.

> So I include the directory containing the header for the library.. and
> thousands of errors are generated from the libwebsocket library.
> Clearly, something must've gone wrong in the build process.
>
> |l46kok at ubuntu:~/Desktop/websocketserver$ arm-linux-gcc test.c -lwebsockets -o test -I/usr/include
> cc1: warning: include location "/usr/include" is unsafe for cross-compilation

Yes you should heed the above warning ----^

> In file included from test.c:1:
> /usr/include/stdio.h: In function 'sprintf':
> /usr/include/stdio.h:365: error: expected declaration specifiers before '__THROWNL'

Sure they're things your build host local compiler understands but your 
cross toolchain has no idea about.

> /usr/include/stdio.h:372: error: storage class specified for parameter 'vfprintf'
> /usr/include/stdio.h:377: error: storage class specified for parameter 'vprintf'
> /usr/include/stdio.h:380: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__THROWNL'
> /usr/include/stdio.h:388: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__THROWNL'
> /usr/include/stdio.h:392: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__THROWNL'
> /usr/include/stdio.h:414: error: storage class specified for parameter 'vdprintf'
> /usr/include/stdio.h:416: error: storage class specified for parameter 'dprintf'
> /usr/include/stdio.h:426: error: storage class specified for parameter 'fscanf'
> /usr/include/stdio.h:431: error: storage class specified for parameter 'scanf'
> /usr/include/stdio.h:434: error: storage class specified for parameter 'sscanf'
> /usr/include/stdio.h:434: warning: '__nothrow__' attribute ignored
> /usr/include/stdio.h:443: error: storage class specified for parameter 'fscanf'
> /usr/include/stdio.h:443: error: redefinition of parameter 'fscanf'
> /usr/include/stdio.h:425: error: previous definition of 'fscanf' was here
> /usr/include/stdio.h:446: error: storage class specified for parameter 'scanf'
> /usr/include/stdio.h:446: error: redefinition of parameter 'scanf'
> /usr/include/stdio.h:431: error: previous definition of 'scanf' was here
> ...
> |
>
> Here's the sample application that compiled and ran without any issue on
> gcc 4.7.3
>
> http://pastebin.com/PBnbdQiW
>
> I'm genuinely not sure how to fix this issue. The warnings and zlib.h
> missing is suspicious, but I'm not sure what exactly they indicate and
> how it's relevant to my problem. Any help would be appreciated.

These are just the usual cross headaches.

If you want to build against cross libs, you have to put them in the 
right place for your toolchain, and if your toolchain doesn't have a 
"right place" create one and force the cross tools to go there for 
includes and libs.

-Andy

>> Reply to this email directly or view it on GitHub
> <https://github.com/warmcat/libwebsockets/issues/32>.
>




More information about the Libwebsockets mailing list