How to Build part of files in lib_deps?

Hi,there.
I am learning about hardware development recently.
I want add lwip in my project.So I add blow code in .ini file.

lib_deps = https://github.com/lwip-tcpip/lwip.git#STABLE-2_2_0_RELEASE

And now I got error like this:

In file included from c:\users\user\.platformio\packages\toolchain-riscv\riscv-none-embed\include\dirent.h:7,
                 from .pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:56,
                 from .pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\makefsdata.c:20:
c:\users\user\.platformio\packages\toolchain-riscv\riscv-none-embed\include\sys\dirent.h:10:2: error: #error "<dirent.h> not supported"
 #error "<dirent.h> not supported"
  ^~~~~
Compiling .pio\build\genericCH32V307VCT6\lib76d\lwip\apps\snmp\snmp_mib2_tcp.o
In file included from .pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\makefsdata.c:20:
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:173:22: error: unknown type name 'DIR'
 #define _TINYDIR_DIR DIR
                      ^~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:221:2: note: in expansion of macro '_TINYDIR_DIR'
  _TINYDIR_DIR *_d;
  ^~~~~~~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h: In function 'tinydir_open':
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:175:26: warning: implicit declaration of function 'opendir' [-Wimplicit-function-declaration]
 #define _tinydir_opendir opendir
                          ^~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:320:12: note: in expansion of macro '_tinydir_opendir'
  dir->_d = _tinydir_opendir(path);
            ^~~~~~~~~~~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:320:10: warning: assignment to 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  dir->_d = _tinydir_opendir(path);
          ^
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:176:26: warning: implicit declaration of function 'readdir'; did you mean 'rand_r'? [-Wimplicit-function-declaration]
 #define _tinydir_readdir readdir
                          ^~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:331:12: note: in expansion of macro '_tinydir_readdir'
  dir->_e = _tinydir_readdir(dir->_d);
            ^~~~~~~~~~~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:331:10: warning: assignment to 'struct dirent *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  dir->_e = _tinydir_readdir(dir->_d);
          ^
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h: In function 'tinydir_close':
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:177:27: warning: implicit declaration of function 'closedir'; did you mean '_fclose_r'? [-Wimplicit-function-declaration]
 #define _tinydir_closedir closedir
                           ^~~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:440:3: note: in expansion of macro '_tinydir_closedir'
   _tinydir_closedir(dir->_d);
   ^~~~~Compiling .pio\build\genericCH32V307VCT6\lib76d\lwip\apps\snmp\snmp_mib2_udp.o
~~~~~~~~~~~~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h: In function 'tinydir_next':
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:469:10: warning: assignment to 'struct dirent *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  dir->_e = _tinydir_readdir(dir->_d);
          ^
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h: In function 'tinydir_readfile':
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:520:10: error: dereferencing pointer to incomplete type 'struct dirent'
   dir->_e->d_name;
          ^~
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\tinydir.h:547:6: warning: implicit declaration of function 'lstat'; did you mean 'stat'? [-Wimplicit-function-declaration]
  if (lstat(
      ^~~~~
      stat
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\makefsdata.c: At top level:
.pio\libdeps\genericCH32V307VCT6\lwip\src\apps\http\makefsdata\makefsdata.c:89:2: error: #error makefsdata not supported on this platform
 #error makefsdata not supported on this platform
  ^~~~~

Can you tell me how to deal or how to build part files in this git repository?

Oh, you can’t just lib_deps = <lwip repository>. PlatformIO needs to have some information on how to build the library, or it will try to build every file and likely fail. That configuration is usually done with a library.json file: documentation. Filtering specific files / directories is done with srcFilter.

You can see in the build log that it’s building lwip\src\apps\http\makefsdata\makefsdata.c: etc., which is a standalone program (app) meant for more Unix-like platforms that have a filesystem. You’re not supposed to build that as part of the stack. You need to figure out exactly what files to compile or not to compile from the lwIP source tree, what configuration file it needs, what macro settings it needs, et cetera.

Actually, I would not recommend to build lwIP from source at all. You still then have the burden of integrating it with the Ethernet hardware. Instead, use the WCH provided libwchnet.a precompiled library. This is lwIP, with the needed Ethernet glue driver layer, integrated into one precompiled file. Checkout examples like this, they are ready-made and verified to be working.

Thank you for reply. It’s very helpful!