YouCompleteMe doesn't show errors when non standard header is included - c

When I try include gst.h YCM start innoring all error
For example:
#include <math.h>
//#include <gst/gst.h>
main (){ //ycm show error here
int a=0;
int b //and here
}
but
#include <math.h>
#include <gst/gst.h>
main (){ //ycm don't show error here
int a=0;
int b //and here
}
path to gst.h included to .ycm_extra_conf.py . What i miss?

:YcmDiags show all warning and error YCM messages.
You must include all nested headers and then YCM parse your code right.
Also you must install clang lib correct for C/C++ language.

Related

I'm getting implicit declaration of function error in C. What is the reason for this? [duplicate]

My compiler (GCC) is giving me the warning:
warning: implicit declaration of function
Why is it coming?
You are using a function for which the compiler has not seen a declaration ("prototype") yet.
For example:
int main()
{
fun(2, "21"); /* The compiler has not seen the declaration. */
return 0;
}
int fun(int x, char *p)
{
/* ... */
}
You need to declare your function before main, like this, either directly or in a header:
int fun(int x, char *p);
The right way is to declare function prototype in header.
Example
main.h
#ifndef MAIN_H
#define MAIN_H
int some_main(const char *name);
#endif
main.c
#include "main.h"
int main()
{
some_main("Hello, World\n");
}
int some_main(const char *name)
{
printf("%s", name);
}
Alternative with one file (main.c)
static int some_main(const char *name);
int some_main(const char *name)
{
// do something
}
When you do your #includes in main.c, put the #include reference to the file that contains the referenced function at the top of the include list.
e.g. Say this is main.c and your referenced function is in "SSD1306_LCD.h"
#include "SSD1306_LCD.h"
#include "system.h" #include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h> // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
The above will not generate the "implicit declaration of function" error, but below will-
#include "system.h"
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h> // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
#include "SSD1306_LCD.h"
Exactly the same #include list, just different order.
Well, it did for me.
You need to declare the desired function before your main function:
#include <stdio.h>
int yourfunc(void);
int main(void) {
yourfunc();
}
When you get the error: implicit declaration of function it should also list the offending function. Often this error happens because of a forgotten or missing header file, so at the shell prompt you can type man 2 functionname and look at the SYNOPSIS section at the top, as this section will list any header files that need to be included. Or try http://linux.die.net/man/ This is the online man pages they are hyperlinked and easy to search.
Functions are often defined in the header files, including any required header files is often the answer. Like cnicutar said,
You are using a function for which the compiler has not seen a
declaration ("prototype") yet.
If you have the correct headers defined & are using a non GlibC library (such as Musl C) gcc will also throw error: implicit declaration of function when GNU extensions such as malloc_trim are encountered.
The solution is to wrap the extension & the header:
#if defined (__GLIBC__)
malloc_trim(0);
#endif
This error occurs because you are trying to use a function that the compiler does not understand. If the function you are trying to use is predefined in C language, just include a header file associated with the implicit function.
If it's not a predefined function then it's always a good practice to declare the function before the main function.
Don't forget, if any functions are called in your function, their prototypes must be situated above your function in the code. Otherwise, the compiler might not find them before it attempts to compile your function. This will generate the error in question.
The GNU C compiler is telling you that it can find that particular function name in the program scope. Try defining it as a private prototype function in your header file, and then import it into your main file.
I think the question is not 100% answered. I was searching for issue with missing typeof(), which is compile time directive.
Following links will shine light on the situation:
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Typeof.html
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Alternate-Keywords.html#Alternate-Keywords
as of conculsion try to use __typeof__() instead. Also gcc ... -Dtypeof=__typeof__ ... can help.

Getting error unknown type name 'size_t' even though I've included the relevant C libraries and headers

Please find my code below.
I am getting the error "/usr/include/linux/sysctl.h:40:2: error: unknown type name ‘size_t’"
Searching online, the only suggestion is to make sure you have stddef.h included in your code, which I do as can be seem below. There does not appear to be a solution available outside of this fix, which I have tried, so I am currently at a loss as to how to move forward.
Also note, this code is not pretty, but that is not the main issue with this thread. The error I am getting does not look like it is being thrown from a mistake in my code, but I may be wrong.
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <sys/types.h>
#include <linux/module.h>
#include <stddef.h>
struct nf_hook_ops{
struct list_head *list;
nf_hookfn *hook;
struct module *owner;
u_int8_t pf;
unsigned int hooknum;
int priority; /* Hooks are ordered in ascending priority. */
};
int nf_register_hook(struct nf_hook_ops *reg);
void nf_unregister_hook(struct nf_hook_ops *reg);
struct nf_hook_ops nfho = {
nfho.hook = hook_func_in,
nfho.hooknum = NF_INET_LOCAL_IN,
nfho.pf = PF_INE,
nfho.priority = NF_IP_PRI_FIRST
};
nf_register_hook(&nfho); // Register the hook
C is parsed strictly top to bottom, and #include does plain old textual inclusion, not anything clever that would qualify for the name of "module import". Therefore, the order of #include directives can matter. In this case, you're getting complaints about a type defined by stddef.h, so you must make sure that stddef.h is included before whatever needs it, which could be (indeed, is) another header file.
I can reproduce the error you're getting with the following two-line source file:
#include <linux/sysctl.h>
#include <stddef.h>
→
$ gcc -fsyntax-only test.c
In file included from test.c:1:0:
/usr/include/linux/sysctl.h:39:2: error: unknown type name ‘size_t’
If I exchange the order of the #include lines,
#include <stddef.h>
#include <linux/sysctl.h>
then there is no error. This is a bug in linux/sysctl.h, but I would not hold my breath for it to be fixed. I recommend moving stddef.h to the very top of the include list.
I can not reproduce the problem with your actual list of includes,
#include <linux/netfilter_ipv4.h>
#include <linux/netfilter.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <sys/types.h>
#include <linux/module.h>
#include <stddef.h>
but a gcc -H dump does not show linux/sysctl.h getting pulled in transitively by that set of includes, so probably it's just that I have a different version of the kernel headers on my Linux box than you do.

linked list gives this warnings [duplicate]

My compiler (GCC) is giving me the warning:
warning: implicit declaration of function
Why is it coming?
You are using a function for which the compiler has not seen a declaration ("prototype") yet.
For example:
int main()
{
fun(2, "21"); /* The compiler has not seen the declaration. */
return 0;
}
int fun(int x, char *p)
{
/* ... */
}
You need to declare your function before main, like this, either directly or in a header:
int fun(int x, char *p);
The right way is to declare function prototype in header.
Example
main.h
#ifndef MAIN_H
#define MAIN_H
int some_main(const char *name);
#endif
main.c
#include "main.h"
int main()
{
some_main("Hello, World\n");
}
int some_main(const char *name)
{
printf("%s", name);
}
Alternative with one file (main.c)
static int some_main(const char *name);
int some_main(const char *name)
{
// do something
}
When you do your #includes in main.c, put the #include reference to the file that contains the referenced function at the top of the include list.
e.g. Say this is main.c and your referenced function is in "SSD1306_LCD.h"
#include "SSD1306_LCD.h"
#include "system.h" #include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h> // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
The above will not generate the "implicit declaration of function" error, but below will-
#include "system.h"
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h> // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
#include "SSD1306_LCD.h"
Exactly the same #include list, just different order.
Well, it did for me.
You need to declare the desired function before your main function:
#include <stdio.h>
int yourfunc(void);
int main(void) {
yourfunc();
}
When you get the error: implicit declaration of function it should also list the offending function. Often this error happens because of a forgotten or missing header file, so at the shell prompt you can type man 2 functionname and look at the SYNOPSIS section at the top, as this section will list any header files that need to be included. Or try http://linux.die.net/man/ This is the online man pages they are hyperlinked and easy to search.
Functions are often defined in the header files, including any required header files is often the answer. Like cnicutar said,
You are using a function for which the compiler has not seen a
declaration ("prototype") yet.
If you have the correct headers defined & are using a non GlibC library (such as Musl C) gcc will also throw error: implicit declaration of function when GNU extensions such as malloc_trim are encountered.
The solution is to wrap the extension & the header:
#if defined (__GLIBC__)
malloc_trim(0);
#endif
This error occurs because you are trying to use a function that the compiler does not understand. If the function you are trying to use is predefined in C language, just include a header file associated with the implicit function.
If it's not a predefined function then it's always a good practice to declare the function before the main function.
Don't forget, if any functions are called in your function, their prototypes must be situated above your function in the code. Otherwise, the compiler might not find them before it attempts to compile your function. This will generate the error in question.
The GNU C compiler is telling you that it can find that particular function name in the program scope. Try defining it as a private prototype function in your header file, and then import it into your main file.
I think the question is not 100% answered. I was searching for issue with missing typeof(), which is compile time directive.
Following links will shine light on the situation:
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Typeof.html
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Alternate-Keywords.html#Alternate-Keywords
as of conculsion try to use __typeof__() instead. Also gcc ... -Dtypeof=__typeof__ ... can help.

How to call a function from another file into main function in c?

I am using qt and created a c project. I have created two files one header file and source file. I have declare a function into header file. So that I can call it from main function. But when I compile and run, I got "undefined reference to " error. How to solve this issue ? I am using qt 5.5 ide.
My Code:
header file
chapter_1.h
#ifndef CHAPTER_1_H
#define CHAPTER_1_H
//include all header files
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
/* function declaration */
int sum(int x, int y);
#endif // CHAPTER_1_H
source file
//include header files
#include "chapter_1.h"
int sum(int x, int y)
{
int result = x+y;
return result;
}
main file:
#include "chapter_1.h"
int main()
{
sum(23, 23);
return 0;
}
It's not a compiler error. It's a linker error. You just need to include both source files (main.cpp and chapter1.cpp) into your project.
I solved the problem. The problem was, file created as .cpp. Now I have changed it into .c and not it worked. Thanks to all.
You must tell the qmake which are the source files that you want to use to generate program. There is a couple of variables defined in project file ( *.pro) which are responsible for this and other information. SOURCES defines the source files to use, HEADERS - you guessed, the headers.
HEADERS = chapter_1.h
SOURCES = main.cpp chapter_1.cpp

bad include syntax Error in minix

#include <lib.h>
#include <unistd.h>
int mq_close(int queue)
{
message m;
m.m3_i1= queue;
return (_syscall(PM_PROC_NR,MQ_CLOSE,&m));
}
While I am updating my libraries in minix I am getting this error "bad include syntax error".. Help me out in this.
Change
#include <lib.h>
into
#include <minix/lib.h>
Assuming you installed minix using the guide.

Resources