This is an issue that's been in the SDK for a while, hopefully it should be simple to fix. The problem is that when a new lwIP SDK project is created, unnecessary directories are added to the C/C++ includes. In some use cases, these unneeded include directories can cause compilation failures.
Here are all of the include directories created for a new SDK 2.6 RT1050 lwIP project:
The issue is that most of those directories don't need to be there, because of how #include statements are employed in the lwIP stack. For instance, look at lwip/src/core/netif.c:
#include "lwip/opt.h"
#include <string.h> /* memset */
#include <stdlib.h> /* atoi */
#include "lwip/def.h"
#include "lwip/ip_addr.h"
#include "lwip/ip6_addr.h"
#include "lwip/netif.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/udp.h"
#include "lwip/priv/raw_priv.h"
#include "lwip/snmp.h"
#include "lwip/igmp.h"
#include "lwip/etharp.h"
#include "lwip/stats.h"
#include "lwip/sys.h"
#include "lwip/ip.h"
#if ENABLE_LOOPBACK
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
#include "lwip/tcpip.h"
#endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */
#endif /* ENABLE_LOOPBACK */
#include "netif/ethernet.h"
All of the lwIP-specific includes are preceded by a relative path, either "lwip/" or "netif/". So there's no need to call out "../lwip/src/include/lwip" and "../lwip/src/include/netif" separately; by specifying "../lwip/src/include", the compiler will find the "lwip" and "netif" subdirectories.
The errors that I run into involve errno.h, and the include path that induces the failure is "../lwip/src/include/lwip". Here's the source for lwip/src/include/lwip/errno.h:
#ifndef LWIP_HDR_ERRNO_H
#define LWIP_HDR_ERRNO_H
#include "lwip/opt.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef LWIP_PROVIDE_ERRNO
[... whole bunch of error number definitions ...]
#else /* LWIP_PROVIDE_ERRNO */
/* Define LWIP_ERRNO_STDINCLUDE if you want to include <errno.h> here */
#ifdef LWIP_ERRNO_STDINCLUDE
#include <errno.h>
#else /* LWIP_ERRNO_STDINCLUDE */
/* Define LWIP_ERRNO_INCLUDE to an equivalent of <errno.h> to include the error defines here */
#ifdef LWIP_ERRNO_INCLUDE
#include LWIP_ERRNO_INCLUDE
#endif /* LWIP_ERRNO_INCLUDE */
#endif /* LWIP_ERRNO_STDINCLUDE */
#endif /* LWIP_PROVIDE_ERRNO */
#ifdef __cplusplus
}
#endif
#endif /* LWIP_HDR_ERRNO_H */
What this header file allows is one of three things:
For maximum compatibility, I have LWIP_PROVIDE_ERRNO undefined and LWIP_ERRNO_STDINCLUDE defined, meaning that I want my project to pull in the Newlib/Redlib copy of errno.h. The problem is that by adding "../lwip/src/include/lwip" to the include paths, saying #include <errno.h> (line 18 above) will always find the lwIP copy first, not the system library copy. This causes lwip/src/include/lwip/errno.h to be included again, which of course does nothing (double-inclusion locks), and the net result is that no errno definitions are added to the project. This of course will cause a compilation error for any module that tries to use an errno code.
Bottom line, it's unnecessary and incorrect to add every single subdirectory in the lwip tree to the include path. An SDK example project or application (which uses LWIP_PROVIDE_ERRNO) should include these paths:
Since I modified my project to use LWIP_ERRNO_STDINCLUDE, I omit the last path (compat/stdc), so that #include <errno.h> finds the Newlib/Redlib header file. Some of the other middleware components also add more include paths than necessary to the project, but this was the only instance I found where the extra include paths cause a compilation error (if LWIP_ERRNO_STDINCLUDE is used).
David R.
Solved! Go to Solution.
Hi David:
Thank you very much for your feedback, I will forward this to software team.
Regards
Daniel
Hi David:
Thank you very much for your feedback, I will forward this to software team.
Regards
Daniel