Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

including <net/socket.h> fails with redefinition of 'struct zsock_timeval' (sometimes :-) ) #41503

Closed
boaks opened this issue Dec 29, 2021 · 8 comments · Fixed by #41916
Closed
Assignees
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@boaks
Copy link

boaks commented Dec 29, 2021

I'm using nRFConnect 1.8.0 and zephyr v2.7.0-ncs1.

If I include <net/socket.h> always as the first, then some files compile well, and some reports

5> In file included from /ncs/zephyr/include/net/socket.h:29,
5> /ncs/zephyr/include/net/socket_select.h:112:17:Kerror: redefinition of 'struct zsock_timeval'
5> In file included from /ncs/zephyr/include/net/socket_select.h:18,
5> from /ncs/zephyr/include/net/socket.h:29,
5> /ncs/zephyr/include/net/socket_types.h:43:8:note: originally defined here

The files are added to the project with

target_sources(app PRIVATE src/a???.c)
target_sources(app PRIVATE src/b???.c)

both file use the same first include

#include <net/socket.h>

For one, it works, for the other it fails. If I remove the failing from the project, the build finishes.
That is very irritating. Has someone similar experience?

@boaks boaks added the bug The issue is a bug, or the PR is fixing a bug label Dec 29, 2021
@boaks
Copy link
Author

boaks commented Dec 29, 2021

I found, that the failing c-file includes <sys/time.h>.

@dkalowsk dkalowsk added priority: low Low impact/importance bug area: Networking labels Jan 4, 2022
@boaks
Copy link
Author

boaks commented Jan 7, 2022

I use now HAVE_SYS_TIME_H in my files to exclude the header.

@gmarull
Copy link
Member

gmarull commented Jan 7, 2022

may be related #41543

@boaks
Copy link
Author

boaks commented Jan 9, 2022

The header <sys/time.h> is part of the compiler tool-chain (gcc-arm-none-eabi-9-2019-q4-major, arm-none-eabi/include/sys). I guess, for other processor families, this may be not the case.
I'm not sure, what fits/fixes best. Either try to exclude the "toolchain headers" or try to include them conditionally. At least it's hard to see, what went wrong, if the compiler includes such header, which are not really supported.
In my case the easiest way was just to "exclude" it within my sources.

@rlubos
Copy link
Contributor

rlubos commented Jan 18, 2022

@boaks I've submitted #41916 with my proposal to address the issue.

The core problem was #define timeval zsock_timeval - if the standard header was included after that, the standard struct timeval definition ended up as a redefinition of struct zsock_timeval>

Another thing is that I don't really see a reason for the socket layer to provide its own definition struct zsock_timeval - from what I've seen every libc library we use in Zephyr has this type defined. So in order to fix the issue, I've reused the standard type (struggled a bit with native_posix libc, since it seems to define the type in a different header than newlib or minimal libc) instead of redefining it at the socket layer.

@boaks
Copy link
Author

boaks commented Jan 18, 2022

#41916 works for me.

@boaks
Copy link
Author

boaks commented Jan 18, 2022

Should I close the issue?

@rlubos
Copy link
Contributor

rlubos commented Jan 19, 2022

Should I close the issue?

No need to, GH will close it automatically once the fix is actually merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants