Problem building project in Eclipse - c

While building a project in Eclipse I got the following output:
make all
Building file: ../Source/gettimeofday.c
Invoking: GCC C Compiler
gcc -I"/root/Desktop/Eclipse/openwsman/Header" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -
MF"Source/gettimeofday.d" -MT"Source/gettimeofday.d" -o"Source/gettimeofday.o" "../Source/gettimeofday.c"
../Source/gettimeofday.c:38: warning: ‘struct timezone’ declared inside parameter list
../Source/gettimeofday.c:38: warning: its scope is only this definition or declaration, which is probably not
what you want
../Source/gettimeofday.c: In function ‘gettimeofday’:
../Source/gettimeofday.c:41: error: dereferencing pointer to incomplete type
../Source/gettimeofday.c:41: error: dereferencing pointer to incomplete type
make: *** [Source/gettimeofday.o] Error 1
The problematic line is:
int gettimeofday(struct timeval *tv, struct timezone *tzp)
This function is declared in the header file.
Can you help me?

GCC complains that struct timezone is undeclared. A few lines down in the file it complains about dereferencing a pointer to an incomplete type. I suspect that gettimeofday.c:41 uses the tzp argument. Did you include a declaration for struct timezone? On my system, it is declared in /usr/include/linux/time.h.

Related

SQLite3: extract column blob. Impossible to load_extension fileio.c

I'm very rookie on SQL and database but my final target is extract all the blob images from a database filed but this is impossible to me. I'm using SQLite and DB Browser for SQLite but I don¡t know how to load the extension.
I have tried to load the fileio.c as extension by the "Load Extension", but Browser only detects .dll and .so.
Ok, I'm trying then to build the fileio.c file by MinGW like this:
C:\Users\juan_>gcc -g -shared ext\misc\fileio.c -o fileio.dll
But then, the compilation doesn't find sqlite3ext.h neither sqlite3.c.
I have downloaded these files from sqlite amalgamation, but now, there is other problem while building:
C:\Users\juan_>gcc -g -shared sqlite-amalgamation-3400100\fileio.c -o fileio.dll
sqlite-amalgamation-3400100\fileio.c:99:30: fatal error: test_windirent.h: No such file or directory
# include "test_windirent.h"
Then, I have found this file in one folder inside sqlite-master (from github, where i could find fileio.c extension).
I add all the amalgamation files in src folder, and retry the building:
sqlite-master\src\fileio.c: In function 'writefileFunc':
sqlite-master\src\fileio.c:513:9: warning: implicit declaration of function 'S_ISLNK' [-Wimplicit-function-declaration]
if( S_ISLNK(mode) ){
^~~~~~~
sqlite-master\src\fileio.c: At top level:
sqlite-master\src\fileio.c:567:3: error: unknown type name 'DIR'
DIR *pDir; /* From opendir() */
^~~
sqlite-master\src\fileio.c: In function 'fsdirResetCursor':
sqlite-master\src\fileio.c:648:22: warning: implicit declaration of function 'closedir' [-Wimplicit-function-declaration]
if( pLvl->pDir ) closedir(pLvl->pDir);
^~~~~~~~
sqlite-master\src\fileio.c: In function 'fsdirNext':
sqlite-master\src\fileio.c:711:18: warning: implicit declaration of function 'opendir' [-Wimplicit-function-declaration]
pLvl->pDir = opendir(pLvl->zDir);
^~~~~~~
sqlite-master\src\fileio.c:711:16: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
pLvl->pDir = opendir(pLvl->zDir);
^
sqlite-master\src\fileio.c:720:29: warning: implicit declaration of function 'readdir' [-Wimplicit-function-declaration]
struct dirent *pEntry = readdir(pLvl->pDir);
^~~~~~~
sqlite-master\src\fileio.c:720:29: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
sqlite-master\src\fileio.c:722:17: error: dereferencing pointer to incomplete type 'struct DIRENT'
if( pEntry->d_name[0]=='.' ){
^~
Is this not the way to get the fileio.dll extension? I hear other kind of advise like using other program or something like that.

Pedantic warning in use of G_DEFINE_BOXED_TYPE

I recently came across the following warning in one of my applications that uses the GLib:
warning: ISO C prohibits argument conversion to union type [-Wpedantic]
note: in definition of macro '_G_DEFINE_BOXED_TYPE_BEGIN'
2147 | _g_register_boxed (g_intern_static_string (#TypeName), copy_func, free_func);
I usually compile with -wpedantic and it was the first time for me to get a warning that couldn't be traced down to my code, but seems to be caused by the internals of the _G_DEFINE_BOXED_TYPE_BEGIN-macro. The warning seems to appear whenever G_DEFINE_BOXED_TYPE is used with a dedicated free or copy function.
An example application may look as the following:
/* boxed_warning.c
* Produces warning, when compiled with:
* $ cc `pkg-config --cflags glib-2.0` -Wextra -Wpedantic -Wall -std=gnu11 -O0 -g -o 'boxed_warning.c.o' -c boxed_warning.c
*/
#include <glib.h>
#include <gio/gio.h>
struct _FooBoxed { gdouble x; };
typedef struct _FooBoxed FooBoxed;
static FooBoxed *
foo_boxed_copy (const FooBoxed *boxed)
{
FooBoxed *result = g_new (FooBoxed, 1);
*result = *boxed;
return result;
}
G_DEFINE_BOXED_TYPE (FooBoxed, foo_boxed, (GBoxedCopyFunc) foo_boxed_copy, (GBoxedFreeFunc) g_free)
I'm using glib 2.62.4, but I can reproduce the warning even when compiling with the latest version from git.gnome.org.
Has anyone else experienced this warning when working with the GLib2.0 and found a work-around? Or is the warning indeed related to a wrong usage of the mentioned macro by my code?

No warnings for headers included by headers in non-current directories

How can I let gcc and clang generate warnings for header files included by header files in non-current directories?
I'm using gcc 4.9.2 and clang 3.6.0.
For example, assume that ./include_a.c includes ./dir/a.h, ./dir/a.h includes ./b.h, and ./b.h is expected to generate a warning for -Wconversion; then, gcc and clang with -Wconversion DO NOT generate the expected warning when they compile include_a.c. With -Wconversion -Wsystem-headers, the expected warning is generated, but it often comes with many useless warnings for system headers. When ./b.h is directly included from a source file in the current directory (such as ./include_b.c), the expected warning is generated without -Wsystem-headers.
The following shell script reproduces this example (the case of clang is omitted):
#!/bin/sh
mkdir dir
echo '#include "b.h"' >dir/a.h
echo 'void f() {int a = 0; char b = a;}' >b.h
echo '#include "dir/a.h"' >include_a.c
echo '#include "b.h"' >include_b.c
set -x
gcc -c include_a.c -Wconversion # DOES NOT generate a warning
gcc -c include_a.c -Wconversion -Wsystem-headers # generate a warning
gcc -c include_b.c -Wconversion # generate a warning
Output:
+ gcc -c include_a.c -Wconversion
+ gcc -c include_a.c -Wconversion -Wsystem-headers
In file included from dir/a.h:1:0,
from include_a.c:1:
./b.h: In function ‘f’:
./b.h:1:31: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]
void f() {int a = 0; char b = a;}
^
+ gcc -c include_b.c -Wconversion
In file included from include_b.c:1:0:
b.h: In function ‘f’:
b.h:1:31: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]
void f() {int a = 0; char b = a;}
^
This behavior seems not to be a bug because gcc and clang perform in the same way, but how can I obtain warnings from all the my source files?

gcc4.9, disable include files trace, from warnings

I just moved to gcc4.9 . Now when I run make to compile my program, I noticed the verbosity of messages is much increased. In particular in the warnings, I receive a lot more of info I don't need, mainly such messages:
myfile.c: In function 'myfunc':
myfile.c:4677:10: warning: passing argument 1 of 'sprintf' from incompatible pointer type
sprintf(str1,"file.txt");
^
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from myfile.c:28:
/usr/include/i386-linux-gnu/bits/stdio2.h:31:1: note: expected 'char * __restrict__' but argument is of type 'char **'
__NTH (sprintf (char *__restrict __s, const char *__restrict __fmt, ...))
^
My compilation parameters are always the same "-g -O3".
I tried -g0 and -g1, but verbosity doesn't lower.
So wanted to ask, how can I set gcc to suppress all those excessive compile-time messages in the warnings, everything starting from "In file included..." and after?
EDIT:
I guess I have to elaborate more what I want to achieve.
I want the warnings, so I don't need -w option.
I do want to see:
myfile.c: In function 'myfunc':
myfile.c:4677:10: warning: passing argument 1 of 'sprintf' from incompatible pointer type
sprintf(str1,"file.txt");
^
I do NOT want to see:
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from myfile.c:28:
/usr/include/i386-linux-gnu/bits/stdio2.h:31:1: note: expected 'char * __restrict__' but argument is of type 'char **'
__NTH (sprintf (char *__restrict __s, const char *__restrict __fmt, ...))
I'm not interested that primitive sprintf is declared in a,called by b (...who actually could be interested in that...?!?)
The previous gcc version didn't have that issue, so my best guess, there must be some new option in gcc4.9 to remove that (but I couldn't find it)
Does anybody know how to remove everything starting from "In file included..." further(in the warning)?
Thanks
I strongly recommend you don't do this, but if you insist:
gcc -w inhibits all warnings. This is something you could have discovered from googling 'gcc suppress warnings'. . .
That said, the warnings are valid - you appear to be doing wrong things in your code. If you want to get rid of the warnings, why not fix the code? Then you have better code and no warnings.
What you suggest is a workaround, but I can still try it. Could you please write here that filter you talk about?
OK; I'd create a shell script to do the hard work. There are two ways to handle it. One is to call the script gcc-filter and then instead of running:
gcc -g -O3 -Wall -Wextra -Werror -I/where/ever -c source.c
you would run:
gcc-filter gcc -g -O3 -Wall -Wextra -Werror -I/where/ever -c source.c
Using make, you can achieve that by specifying CC="gcc-filter gcc" or equivalent.
The alternative is to run the script after redirecting output:
gcc -g -O3 -Wall -Wextra -Werror -I/where/ever -c source.c 2>&1 | gcc-filter
I'm going to assume the first technique.
gcc-filter.sh
"$#" 2>&1 |
sed '/^In file /,/^ *^/d' >&2
The first line runs gcc (or whatever command is specified by the arguments; it doesn't have to be gcc) with the arguments as specified on the command line. It redirects both standard output and standard error to a pipe (I'll come back to this), which goes to sed.
The sed line looks for the pattern In file at the start of a line, and deletes from there up to the first line that starts with a caret after optional spaces. The redirection sends the information that it passes through to standard error.
There are two prime defects with the script as it stands:
It assumes that standard output and standard error can be merged (or, more succinctly, that gcc doesn't write much to standard output).
It works off one pattern of error reporting. If there are other sequences that should be filtered, you will need to add to the sed script.
You can deal with the standard output vs standard error issue, but it is mildly mind blowing (maybe 'mind puffing').
(
"$#" 2>&1 1>&3 |
sed '/^In file /,/^ *^/d' >&2
) 3>&1
The sub-shell ( ... ) 3>&1 sends data written to file descriptor 3 so it goes to standard output.
Inside the sub-shell 2>&1 1>&3 | arranges for:
Standard output to go to the pipe.
Standard error to go where standard output is going (the pipe).
Standard output to go to file descriptor 3 (without changing where standard error is going, the pipe).
The sed command therefore gets the standard error output from gcc as its standard input, filters it, and the >&2 sends its standard output to standard error.
The net result is that standard error is filtered while standard output is not. However, be aware that you can end up with different interleaving of output from the two streams as a result of the buffering going on.
One other problem: exit status. The exit status of the script as written is the exit status of the sed command, which will be 0 under most circumstances. If we need to relay the exit status from gcc, we have to work with the Bash set -o pipefail, I think. Or you can poke at the PIPESTATUS array; exit ${PIPESTATUS[0]} should exit with the same exit status that gcc exited with.
Demonstrating the code working on Linux
The system is running an Ubuntu 14.04 LTS derivative with GCC 4.9.2.
Test code b.c
(I'd used up x.c, y.c, z.c, and a.c on other programs.)
#include <stdio.h>
int main(void)
{
char array[512];
char *buffer = array;
sprintf(&buffer, "file.txt");
printf("%s\n", buffer);
return 0;
}
Compilation without gcc-filter.sh:
$ make b.o WFLAG3= WFLAG4= WFLAG5= WFLAG6= IFLAGS= LDFLAGS= LDLIBS= cc -g -O3 -std=c11 -Wall -Wextra -Werror -c -o b.o b.c
b.c: In function ‘main’:
b.c:8:3: error: passing argument 1 of ‘sprintf’ from incompatible pointer type [-Werror]
sprintf(&buffer, "file.txt");
^
In file included from /usr/include/features.h:374:0,
from /usr/include/stdio.h:27,
from b.c:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:31:1: note: expected ‘char * restrict’ but argument is of type ‘char **’
__NTH (sprintf (char *__restrict __s, const char *__restrict __fmt, ...))
^
cc1: all warnings being treated as errors
<builtin>: recipe for target 'b.o' failed
make: *** [b.o] Error 1
$
Compilation with gcc-filter.sh
$ make b.o CC="./gcc-filter.sh gcc"
./gcc-filter.sh gcc -g -O3 -std=c11 -Wall -Wextra -Werror -c -o b.o b.c
b.c: In function ‘main’:
b.c:8:11: error: passing argument 1 of ‘sprintf’ from incompatible pointer type [-Werror]
sprintf(&buffer, "file.txt");
^
cc1: all warnings being treated as errors
<builtin>: recipe for target 'b.o' failed
make: *** [b.o] Error 1
$
gcc-filter.sh
#!/bin/bash
set -o pipefail
(
"$#" 2>&1 1>&3 |
sed '/^In file /,/^ *^/d' >&2
) 3>&1
exit ${PIPESTATUS[0]}
And another test
I also created c.c which contained three sprintf() lines and three printf() lines, and the filtered output was:
$ ./gcc-filter.sh gcc -g -O3 -std=c11 -Wall -Wextra -Werror -c c.c
c.c: In function ‘main’:
c.c:8:11: error: passing argument 1 of ‘sprintf’ from incompatible pointer type [-Werror]
sprintf(&buffer, "file1.txt");
^
c.c:10:11: error: passing argument 1 of ‘sprintf’ from incompatible pointer type [-Werror]
sprintf(&buffer, "file2.txt");
^
c.c:12:11: error: passing argument 1 of ‘sprintf’ from incompatible pointer type [-Werror]
sprintf(&buffer, "file3.txt");
^
cc1: all warnings being treated as errors
$
So multiple errors are handled properly (but in times past, more than one similar script has appeared to work on a single instance of an error message but when tested on multiple error messages, it was too enthusiastic about discarding output).

GCC does not throw an error during the compiler stage when a function has not been forward declared

Ok,
I have 3 files in my directory.
main.c
#include <stdio.h>
int main(int a, int b, int c)
{
aprint();
bprint();
}
a.c
#include <stdio.h>
void aprint()
{
printf("hey This is a.c");
}
b.c
#include <stdio.h>
void bprint()
{
printf("This is b.c");
}
I haven't created any header files.
I just compiled using "gcc main.c a.c b.c"
I didn't get any error. I want to know what happened?
Did gcc just assume everything is going to be okay in linking stages and why didn't gcc throw an error during compilation?
Enable warnings using -Wall flag, hten you will see warning: Implicit call to function bprint() and Implicit call to function aprint(). It's is basically compiler recognizes this function during Linker stage and this does not give any error.
C89/90 version of C language does not require functions to be forward declared. C99 version of C language does require functions to be forward declared. Are you compiling your code in C89/90 mode or in C99 mode?
Note that even in C99 mode a genuine error (i.e. a constraint violation) might be reported by the compiler as a mere warning. If you want GCC to become more strict in reporting constraint violations as errors, run it with -pedantic-errors switch.
I brought you your warnings:
notroot#ubuntu:~/qweqwe$ gcc main.c a.c b.c -Wall
main.c:2:5: warning: second argument of ‘main’ should be ‘char **’ [-Wmain]
main.c:2:5: warning: third argument of ‘main’ should probably be ‘char **’ [-Wmain]
main.c: In function ‘main’:
main.c:4:1: warning: implicit declaration of function ‘aprint’ [-Wimplicit-function-declaration]
main.c:5:1: warning: implicit declaration of function ‘bprint’ [-Wimplicit-function-declaration]
main.c:6:1: warning: control reaches end of non-void function [-Wreturn-type]

Resources