Reputation: 18221
Trying to build paho_c_pub.c with help of Visual Studio 2019 on my Raspberry Pi machine connected via ssh. Code uses structure sigaction
from <signal.h> that is not visible by compiler:
Error invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’
Error storage size of ‘sa’ isn’t known
I have no such errors when I build code in console:
cc paho_c_sub.c pubsub_opts.c -o paho_c_sub -l paho-mqtt3as
What is wrong with Visual Studio C project configuration?
Upvotes: 1
Views: 568
Reputation: 91
Your code needs to have
#define _POSIX_C_SOURCE 200809L
before the
#include <signal.h>
as described in man 3 sigaction, in the Feature Test Macro requirements for glibc part of the Synopsis.
Whenever you compile code, you should enable warnings (-Wall
).
Without the above definition, the sigaction()
function is not exposed, and your compiler uses the standard C rules on determining exactly what to pass to it. It happens to work, because it takes an int and two pointers as parameters; but when warnings are enabled (and especially when warnings are treated as errors, as in your Visual Studio 2019 environment), the compiler points out this issue.
Adding the #define
should make both work correctly, without relying on happenstance.
Upvotes: 1