stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.74k forks source link

warning: implicit declaration of function ‘accept4’; did you mean ‘accept’? [-Wimplicit-function-declaration] #717

Closed ssgnh closed 2 months ago

ssgnh commented 1 year ago

你好,我没有采用生成链接库的方式,采用的是将源码中的 .c文件 和 .h文件 添加到工程目录使用的,并且将生成config.h也添加到工程目录了。将识别不出的文件中的<>符号改成“”了,可以编译通过,并且测试没问题,但是编译时会警告 implicit declaration of function ‘accept4’,未找到原因,请问这个警告怎样消除

我使用的编译指令: gcc -g -o ./bin/app main.c modbus.c modbus-tcp.c modbus-data.c -I ./

编译警告信息: modbus-tcp.c: In function ‘modbus_tcp_accept’: modbus-tcp.c:707:14: warning: implicit declaration of function ‘accept4’; did you mean ‘accept’? [-Wimplicit-function-declaration]

希望得到您的回复,谢谢!

ssgnh commented 1 year ago

编译环境: Ubuntu 20.04 GNU11

akmubi commented 1 year ago

Hi. Try to replace HAVE_ACCEPT4 in config.h with 0:

#define HAVE_ACCEPT4 0

If you need to compile the library with debug info, I suggest doing it with autotools:

./autogen.sh
./configure CFLAGS="-g"
make

results will be in src/.libs/:

$ ls src/.libs/*.o
modbus-data.o  modbus.o  modbus-rtu.o  modbus-tcp.o
stephane commented 2 months ago

No I mean accept4.