Macro incompatibility between lwip/sockets.h and functional libraries

elfalko
Posts: 2
Joined: Fri Jun 30, 2017 9:22 am

Macro incompatibility between lwip/sockets.h and functional libraries

Postby elfalko » Fri Jun 30, 2017 9:38 am

When I try to include the lwip/sockets.h, compilation throws the attached errors.

They seem to come from the fact that both the functional and sockets.h libraries have some different bind macros.
Since the functional library has never caused problems before, I assume the error lies in the combination of the two.

Has anyone experienced similar problems? Do I need to rename one of those macros to avoid this? If yes, is there a more convenient way? I don't really wan't to modify libraries publicly available, that only invites trouble if they get updates.

I will probably try some lower levels of lwip like netconn or raw next, maybe those don't face these restrictions.

Compiler errors:

Code: Select all

CXX Socket.o
CXX Timing.o
In file included from /mnt/hgfs/c/Users/[redacted]/Projects/[redacted]/esp32/os_esp32/./../../components/os/../../components/util/Types.h:9:0,
                 from /mnt/hgfs/c/Users/[redacted]/Projects/[redacted]/esp32/os_esp32/./../../components/os/Socket.h:12,
                 from /mnt/hgfs/c/Users/[redacted]/Projects/[redacted]/esp32/os_esp32/./Socket.cpp:8:
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1462:45: error: macro "bind" requires 3 arguments, but only 2 given
     bind(_Func&& __f, _BoundArgs&&... __args)
                                             ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1490:45: error: macro "bind" requires 3 arguments, but only 2 given
     bind(_Func&& __f, _BoundArgs&&... __args)
                                             ^
In file included from /mnt/hgfs/c/Users/[redacted]/Projects/[redacted]/esp32/os_esp32/./../../components/os/../../components/util/Types.h:9:0,
                 from /mnt/hgfs/c/Users/[redacted]/Projects/[redacted]/esp32/os_esp32/./../../components/os/Socket.h:12,
                 from /mnt/hgfs/c/Users/[redacted]/Projects/[redacted]/esp32/os_esp32/./Socket.cpp:8:
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1462:5: error: 'std::bind' declared as an 'inline' variable
     bind(_Func&& __f, _BoundArgs&&... __args)
     ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1464:7: error: expected primary-expression before 'typedef'
       typedef _Bind_helper<false, _Func, _BoundArgs...> __helper_type;
       ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1464:7: error: expected '}' before 'typedef'
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1464:7: error: expected ';' before 'typedef'
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1465:24: error: '__helper_type' has not been declared
       typedef typename __helper_type::__maybe_type __maybe_type;
                        ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1466:24: error: '__helper_type' has not been declared
       typedef typename __helper_type::type __result_type;
                        ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1467:7: error: expected unqualified-id before 'return'
       return __result_type(__maybe_type::__do_wrap(std::forward<_Func>(__f)),
       ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1473:24: error: expected template-name before '<' token
     : _Bind_check_arity<typename decay<_Func>::type, _BoundArgs...>
                        ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1473:24: error: expected '{' before '<' token
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1473:24: error: expected unqualified-id before '<' token
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1490:5: error: 'bind' declared as an 'inline' variable
     bind(_Func&& __f, _BoundArgs&&... __args)
     ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1492:7: error: expected primary-expression before 'typedef'
       typedef _Bindres_helper<_Result, _Func, _BoundArgs...> __helper_type;
       ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1492:7: error: expected '}' before 'typedef'
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1492:7: error: expected ';' before 'typedef'
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1493:24: error: '__helper_type' has not been declared
       typedef typename __helper_type::__maybe_type __maybe_type;
                        ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1494:24: error: '__helper_type' has not been declared
       typedef typename __helper_type::type __result_type;
                        ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1495:7: error: expected unqualified-id before 'return'
       return __result_type(__maybe_type::__do_wrap(std::forward<_Func>(__f)),
       ^
/home/[redacted]/esp/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1497:5: error: expected declaration before '}' token
     }
     ^
/home/[redacted]/esp/esp-idf/make/component_wrapper.mk:176: recipe for target 'Socket.o' failed
make[1]: *** [Socket.o] Error 1
make[1]: *** Waiting for unfinished jobs....
CXX test.o
/home/[redacted]/esp/esp-idf/make/project.mk:386: recipe for target 'os_esp32-build' failed
make: *** [os_esp32-build] Error 2

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Macro incompatibility between lwip/sockets.h and functional libraries

Postby ESP_igrr » Fri Jun 30, 2017 11:28 am

LwIP defines a bunch of socket functions as macros (read,write,bind,select,etc...).

Ideally, these should be changed to be normal functions instead. That would fix C++ compatibility issues.

I think we will tackle this as part of https://github.com/espressif/esp-idf/issues/273 in the 3.0 release of the ESP-IDF.

elfalko
Posts: 2
Joined: Fri Jun 30, 2017 9:22 am

Re: Macro incompatibility between lwip/sockets.h and functional libraries

Postby elfalko » Fri Jun 30, 2017 1:18 pm

I found a nice and easy workaround:

Code: Select all

#include "lwip/sockets.h"
//NECESSARY to avoid conflicts
#undef bind
It seems only the bind macro is causing problems for now. So unbinding it after the inclusion avoids those.

Who is online

Users browsing this forum: No registered users and 74 guests