missing "linux/ext2_fs.h" in Ubuntu 16.04 [duplicate] - c

cat main.c
#include <stdio.h>
#include <stdlib.h>
#include <linux/ext2_fs.h>
int main(int argc, char** argv) {
return (EXIT_SUCCESS);
}
Here is my output...
gcc main.c In file included from main.c:3:
/usr/include/linux/ext2_fs.h: In function ‘ext2_mask_flags’:
/usr/include/linux/ext2_fs.h:182: error: ‘FS_DIRSYNC_FL’ undeclared
(first use in this function)
/usr/include/linux/ext2_fs.h:182: error: (Each undeclared identifier
is reported only once
/usr/include/linux/ext2_fs.h:182: error: for each function it appears
in.)
/usr/include/linux/ext2_fs.h:182: error: ‘FS_TOPDIR_FL’ undeclared
(first use in this function)
/usr/include/linux/ext2_fs.h:184: error: ‘FS_NODUMP_FL’ undeclared
(first use in this function)
/usr/include/linux/ext2_fs.h:184: error: ‘FS_NOATIME_FL’ undeclared
(first use in this function)
If I remove #include <linux/ext2_fs.h> the program compiles successfully...

You need to add #include <linux/fs.h>

You need to add #include <linux/fs.h> before including the #include <linux/ext2_fs.h>

I had no idea, so I put ext2_fs.h into Google and this was the 4th result.
The behaviour seems to be considered a bug.

I fixed it with:
#include <sys/stat.h>
#include <linux/fs.h>

Related

Windows.h functions not declared - C

I'm trying to write a test program using windows.h. I have a simple main function with a function in it and doesn't work when I compile it:
#include <windows.h>
#include <stdio.h>
int main(){
COORD coords;
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, &coords);
return 0;
}
But when I compile it using "mingw32-gcc main.c" i get:
main.c: In function 'main':
main.c:107:5: warning: implicit declaration of function 'SetConsoleDisplayMode' [-Wimplicit-function-declaration]
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, &coords);
^~~~~~~~~~~~~~~~~~~~~
main.c:107:60: error: 'CONSOLE_FULLSCREEN_MODE' undeclared (first use in this function)
SetConsoleDisplayMode(GetStdHandle(STD_OUTPUT_HANDLE), CONSOLE_FULLSCREEN_MODE, &coords);
^~~~~~~~~~~~~~~~~~~~~~~
main.c:107:60: note: each undeclared identifier is reported only once for each function
(It says it's in line 107 because I wrote additional functions that does not need windows.h and don't cause trouble as I don't use them, also they are commented)

F_GETPIPE_SZ undeclared

I'm trying to get size of pipe:
printf("pipe 0 size: %d bytes\npipe 1 size: %d bytes\n", fcntl(fd[0], F_GETPIPE_SZ), fcntl(fd[1], F_GETPIPE_SZ));
Used headers (half of them used by another parts of code):
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
When I'm trying to compile, gcc fails with this error:
‘F_GETPIPE_SZ’ undeclared (first use in this function)
kernel version - 5.4.0-88-generic
libc6-dev version - 2.31-0ubuntu9.2
gcc version - 4:9.3.0-1ubuntu2
Since this macro is not part of POSIX, you must define the _GNU_SOURCE feature test macro before including <fcntl.h>.
This is stated in the fcntl(2) man page, in the "Conforming To" section.
See What does "#define _GNU_SOURCE" imply?

Trouble using constants in C

In my prototype file, proto.h, I have
#define LOOP_LIMIT 90.00
#define PI 3.14159
#ifndef _PROTO_H
#define _PROTO_H
#include <stdio.h>
#include <math.h>
#include "get_problem.c"
#include "deg_to_rad.c"
#include "evaluate_sin.c"
#include "evaluate_cos.c"
#include "evaluate_tan.c"
int main(void);
int get_problem();
double deg_to_rad(int deg);
void evaluate_sin(int deg);
void evaluate_cos(int deg);
void evaluate_tan(int deg);
#endif
In my lab7.c I have my main function and I include proto.h. When I try to compile on Linux using the "make" command, I get the following message:
gcc -c deg_to_rad.c deg_to_rad.c: In function ‘deg_to_rad’:
deg_to_rad.c:2: error: ‘PI’ undeclared (first use in this function)
deg_to_rad.c:2: error: (Each undeclared identifier is reported only once
deg_to_rad.c:2: error: for each function it appears in.)
make: * [deg_to_rad.o] Error 1
I really don't understand this because my main function uses LOOP_LIMIT correctly, but PI isn't working.
deg_to_rad.c:
double deg_to_rad(int deg) {
double rad = (PI * deg) / 180;
return rad;
}
#include "get_problem.c"
#include "deg_to_rad.c"
#include "evaluate_sin.c"
#include "evaluate_cos.c"
#include "evaluate_tan.c"
NO NO, You shouldn't be including C files!!!
In general, You declare functions in header(.h) files, define them in source files(.c) and include the header files in source files(.c) wherever you need to use the functions.
Also, show the definition of deg_to_rad() function, the compiler clearly tells you the problem lies there, I suspect you try to call one of the other functions in the function.
The compiler rightly complains because the functions are declared after the point where you include the source file.
You need to follow the general practice of header and source files mentioned above.

Trouble with header file

I got the following error on compiling a c code I wrote. I understand that the problem is in the header file. Can anyone please tell me which all header files are needed to define these functions.
sign.c: In function ‘main’:
sign.c:78: warning: assignment makes pointer from integer without a cast
/tmp/ccnsSeHy.o: In function `sign_data_evp':
sign.c:(.text+0x68): undefined reference to `check_ssl_rv'
sign.c:(.text+0xd5): undefined reference to `check_ssl_rv'
sign.c:(.text+0x13e): undefined reference to `check_ssl_rv'
/tmp/ccnsSeHy.o: In function `main':
sign.c:(.text+0x1ca): undefined reference to `initialize'
sign.c:(.text+0x1d6): undefined reference to `select_engine'
sign.c:(.text+0x20a): undefined reference to `sign_data'
sign.c:(.text+0x216): undefined reference to `clean_engine'
sign.c:(.text+0x21b): undefined reference to `clean_up'
collect2: ld returned 1 exit status
The header files that I have used so far is:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <netdb.h>
#include <unistd.h>
#ifdef __VMS
#include <socket.h>
#include <inet.h>
#include <in.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
Operating platform: Linux
Thanks in advance.
You understand it wrong. It does not complain about unknown function prototype, it complains during the linking. So you probably forgot to link with some library or some object file.
try with this
gcc sslprogname.c -o sslprogname -Wl,-Bstatic -lssl -Wl,-Bdynamic -lssl3 -lcrypto.It worked for me

declaring global variables in yacc

I have a few source code files, such hashtable.c and such. The main issue is that when I write my main.c as such:
#include "tokens.h"
#include <stdio.h>
void yyerror(char *errorMsg)
{
fprintf(stderr, "%s\n", errorMsg);
}
main()
{
yyparse();
hsh = createHashtable();
}
And at the top of my yacc file (parser.y), I want to declear a hash table as such:
%{
#include <stdio.h>
#include "tokens.h"
#include "ast.c"
struct hashtable *hsh;
.............................
..............................
However I am getting this error.
main.c: In function ‘main’:
main.c:24: error: ‘hsh’ undeclared (first use in this function)
main.c:24: error: (Each undeclared identifier is reported only once
main.c:24: error: for each function it appears in.)
make: *** [main.o] Error 1
I am rather naive while it comes to C programming, any assistance will be greatful
You need an extern struct hashtable* hsh; in your main.c

Resources