How to fix error from structmember.h when compiling with g++ - c

I made a python script that I wanted to compile to an executable. I used cython first, to create a .c file and then I wanted to compile that to an executable with g++. This however causes an error stating that something in structmember.h (which is a header file that comes with python) is apparently wrong.
I have tried to find other people with the same problem, but I couldn't.
I used this to compile:
g++ Training_set.c -o Training_set.exe
The error i got was:
Training_set.c:17362:26: fatal error: structmember.h: No such file or directory
compilation terminated.
structmember.h:21:5 error: 'Py_ssize_t" does not name a type
structmember.h:67:11 error: expected constructor, destructor or type conversion before '(' token
structmember.h:68:17 error: expected constructor, destructor or type conversion before 'Pymember_SetOne'

So i managed to fix my problem, somehow if I put all header files in a subdirectory and provide the path to them with -I it does work.

Related

Is there any way to suppress errors about missing header files in GCC?

I need to check 2 million C source files for a research project for simple syntax errors like missing (semicolons, parenthesis, ...). Each file is a function without main() and header files.
With the help of GCC, I have used the following command:
gcc -c -fsyntax-only -w file.c
My script is doing the job, but the only problem is that almost more than 95% of errors are related to missing header files. I tried to add some of these header files to each function, but the number of these header files seems endless.
Is there any way to suppress errors about missing header files?
Does GCC have a special Flag that I can use for my purpose?
A sample of errors that are related to header files:
error: unknown type name ‘ioreq_t’
error: unknown type name ‘SH7750State’
error: unknown type name ‘int64_t’
error: unknown type name ‘AVCodecContext’
error: unknown type name ‘BlockDriverState’
error: unknown type name ‘PXA2xxLCDState’
Also, I appreciate any other solution besides using GCC.
As workaround, you might create one header which includes all the missing #include and use -include to force that inclusion on top of examined files.
So you don't edit all files:
gcc -include "workaround.h" -c -fsyntax-only -w file.c

including linux headers in c program throwing errors for not finding headers

I am compiling small program with couple of header files and a source file. the code is here
https://elixir.bootlin.com/linux/v5.10/source/tools/testing/selftests/net/psock_tpacket.c
https://elixir.bootlin.com/linux/v5.10/source/tools/testing/selftests/kselftest.h
https://elixir.bootlin.com/linux/v5.10/source/tools/testing/selftests/net/psock_lib.h
It needs kernel header files so I tried something like this
# gcc -I//usr/src/linux-headers-5.10.0-kali7-common/include psock_lib.h kselftest.h psock_tpacket.c -o t.o -I.
But AM getting compilation errors like this
psock_lib.h:50:24: error: array type has incomplete element type ‘struct sock_filter’
1 ⨯
there are number of these errors.
above error simply simply thrown because struct sock_filter not found which exists in linux headers
in my usr/src/ directory
I have linux-headers-5.10.0-kali7-common & linux-headers-5.10.0-kali7-amd64
in gcc command I am specifying -I/usr/src/linux-headers-5.10.0-kali7-common/include is this correct?
both linux-headers-5.10.0-kali7-common/include and linux-headers-5.10.0-kali7-amd64/include have makefile

Netbeans errors with C

I'm trying to do some basic programs in C in NetBeans, it worked well yesterday but now it shows some errors that I can't get rid off. First one shows when I try to compile my main.c file via NetBeans's terminal. I have included 2 files: stdio.h and stdlib.h. They don't show errors in code (it's not highlighted with red underline), only when I try to compile it via terminal. But when I tried to compile file via windows's cmd, it worked. Second error shows when I run program in NetBeans.
1st error: bash-4.4$ gcc main.c -o nav1 main.c:13:19: fatal error: stdio.h: No such file or directory
2nd error: bash.exe: warning: could not find /tmp, please create!

make file fails with unknown type error?

I am attempting to run a make file for a third party piece of software but I am getting an error when I run it:
$ make
gcc -Iinclude/ -Isrc/ -Wall -Wfatal-errors -Ofast -c ./src/gemm.c -o obj/gemm.o
In file included from ./src/gemm.c:2:
In file included from src/utils.h:5:
In file included from src/list.h:3:
include/darknet.h:491:1: fatal error: unknown type name 'pthread_t'
pthread_t load_data(load_args args);
^
1 error generated.
make: *** [obj/gemm.o] Error 1
I'm not very familiar with C, but from what I can tell pthread_t is a datatype that is similar to an int. I looked at the line that is causing the error:
pthread_t load_data(load_args args);
but don't see anything that would be an obvious cause of the problem.
I looked in my make file and I see this line:
LDFLAGS= -lm -pthread
Could this be part of the problem?
Does anyone know what I might need to do in order to get the pthread_t type recognized so I can run the make file?
I apologize if the answer is obvious - I tried googling the specific error message I was getting but didn't turn much up. Please let me know if I need to post any other other code than what I have already included.
Your error comes from not including the pthread library (assuming you are compiling this for a posix compliant system, if you are on windows pthreads are unlikely to work).
See were the pthread library is installed in your machine and include it in the command line.

Fatal Error Message during Compiling

Trying to compile a c file that has the header:
#include <sys/wait.h>
I'm using Cygwin to compile it and it keeps giving me this error whenever I type in gcc minishell.c -o minishell:
minishell.c:4:22: fatal error: sys/wait.h: No such file or directory compilation terminated.
Any clue what the heck is going on?
That's because compiler, in this case, does not know how to reach/find sys/wait.h file so that it can include this file in compilation process. To check which all places compiler will try to find the files, refer:
How to tell C++ library path in Cygwin and MinGW
Above post/link also tells about include paths.

Resources