Rajaram-Regupathy / libtypec

“libtypec” is aimed to provide a generic interface abstracting all platform complexity for user space to develop tools for efficient USB-C port management. The library can also enable development of diagnostic and debug tools to debug system issues around USB-C/USB PD topology.
34 stars 4 forks source link

Warning during build: implicit declaration of function 'nftw'; did you mean 'ftw'? [-Wimplicit-function-declaration] #28

Closed ColinIanKing closed 5 months ago

ColinIanKing commented 8 months ago

Hi,

Building on Debian sid, I'm getting a warning, implicit declaration of function 'nftw'; did you mean 'ftw'? [-Wimplicit-function-declaration]

cmake -DCMAKE_BUILD_TYPE=Release . -- The C compiler identification is GNU 13.2.0 -- The CXX compiler identification is GNU 13.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (0.4s) -- Generating done (0.0s) -- Build files have been written to: /home/cking/repos/libtypec (sid-chroot)cking@t480:~/repos/libtypec$ make [ 10%] Building C object CMakeFiles/libtypec.dir/libtypec.c.o [ 20%] Building C object CMakeFiles/libtypec.dir/libtypec_sysfs_ops.c.o /home/cking/repos/libtypec/libtypec_sysfs_ops.c: In function 'libtypec_sysfs_get_bb_status': /home/cking/repos/libtypec/libtypec_sysfs_ops.c:1059:13: warning: implicit declaration of function 'nftw'; did you mean 'ftw'? [-Wimplicit-function-declaration] 1059 | if (nftw ("/dev/bus/usb/", count_billbrd_if, fd_limit, 0) != 0) | ^~~~ | ftw [ 30%] Building C object CMakeFiles/libtypec.dir/libtypec_dbgfs_ops.c.o [ 40%] Linking C shared library bin/libtypec.so [ 40%] Built target libtypec [ 50%] Building C object utils/CMakeFiles/lstypec.dir/lstypec.c.o [ 60%] Building C object utils/CMakeFiles/lstypec.dir/names.c.o [ 70%] Linking C executable ../bin/lstypec [ 70%] Built target lstypec [ 80%] Building C object utils/CMakeFiles/typecstatus.dir/typecstatus.c.o [ 90%] Building C object utils/CMakeFiles/typecstatus.dir/names.c.o [100%] Linking C executable ../bin/typecstatus [100%] Built target typecstatus

ColinIanKing commented 8 months ago

Looking at the manual, it seems that one needs to define _XOPEN_SOURCE to pick up the prototype for ntfw():

diff --git a/libtypec_sysfs_ops.c b/libtypec_sysfs_ops.c
index a2ab2b8..6a9b07d 100644
--- a/libtypec_sysfs_ops.c
+++ b/libtypec_sysfs_ops.c
@@ -28,6 +28,7 @@ SOFTWARE.
  * @author Rajaram Regupathy <rajaram.regupathy@gmail.com>
  * @brief Functions for libtypec sysfs based operations
  */
+#define _XOPEN_SOURCE 500

 #include "libtypec_ops.h"
 #include <dirent.h>

However, this now throws a build warning because of a missing struct FTW * argument to call back function count_billbrd_if():

 1056 |         if (nftw ("/dev/bus/usb/", count_billbrd_if, fd_limit, 0) != 0)
      |                                    ^~~~~~~~~~~~~~~~
      |                                    |
      |                                    int (*)(const char *, const struct stat *, int)
In file included from /home/cking/repos/libtypec/libtypec_sysfs_ops.c:44:
/usr/include/ftw.h:179:51: note: expected '__nftw_func_t' {aka 'int (*)(const char *, const struct stat *, int,  struct FTW *)'} but argument is of type 'int (*)(const char *, const struct stat *, int)'
  179 | extern int nftw (const char *__dir, __nftw_func_t __func, int __descriptors,
Rajaram-Regupathy commented 5 months ago

resolved