Is it possible to turn off all macro and pasting errors (or errors of any types)?
ie:
error: macro "macro_name" passed 1 arguments, but takes just 0
error: pasting "&" and "0" does not give a valid preprocessing token
The reason is that I'm debugging code that has a bunch of these errors (which I haven't fixed yet) that are making it harder to see the other types of errors that I'm trying to fix first.
No, that's why they're errors instead of warnings; the compiler doesn't know what to do with/how to work around them. You should usually fix errors in the order they come up anyway, especially the preprocessor errors you want to turn off, because an error in one part of the code can propagate and cause "errors" in other, correct, parts of the code. If you're getting too many errors, use make 2>&1 | less to get them without scrolling back.
Pipe the output of the compiler to a text file, and then read the text file to find your errors. You could remove the "un-interesting" errors via RegEx or something similar.
Related
I took Linux kernel version 4.9.30, added a new directory /fsac whose files include headers from other directory (/include/fsac) and that is almost all I changed. Trying to compile I get a lot of errors in /kernel/sched/core.c that look like this:
kernel/sched/core.c:2326:20: error: invalid storage class for function ‘set_schedstats’
kernel/sched/core.c:2342:19: error: invalid storage class for function ‘setup_schedstats’
(...)
Searching on-line I saw that the recommendation was to simply remove the 'static' from the functions. Doing that effectively avoided that errors, but instead I started getting a lot of warnings from objtool like "frame pointer state mismatch" for each of the functions whose static was removed.
I discovered these warnings can be avoided by changing in the configuration file CONFIG_STACK_VALIDATION=n. That worked but even though there is no warning, compilation fails (Error 2).
Hence, I am wondering:
1 - Is the removal of "static" from the offended functions the proper solution?
2 - If so, how do I deal with the objtool warnings? Can those warnings alone constitute a compilation error, or there must be something else?
3 - Do you think I should degrade GCC?
This is the source code of the project: https://github.com/Zildj1an/FSAC_Kernel
This is the compilation log w/o removing the statics: https://github.com/Zildj1an/FSAC_Kernel/blob/master/build_err
I will happily provide any other information you might need.
Cheers.
Problem found, I had a function inside a function... Probably was moved copying something else.
I am new to C. I encountered an error message which involves unexpected "}". However, I checked the number of "}" with an editor and indeed they pair up.
Then I wonder if there is a compiler command, so the compilation can stop whatever I want? It will be convenient to have such tool as debug help.
Thank you.
(Edited in 29-10-2015)
I typically write my code with gedit. Nonetheless, since my work is mostly done on cluster, it will be troublesome to transport the files up and down. I must turn to nano, vi or vim which causes difficulty in debugging.
Stopping compilation partway through is rarely a useful feature. You'll want to see all of the errors that may exist in your code so you can fix more that just one at a time.
That said, an error such as a misplaced brace or parenthesis can cascade down and cause several more errors to appear. So if you see a long list of errors that don't seem to make sense when you look at the code, start at the top and fix that, then recompile to see if it took care of any others.
The answer is no compilers are all or nothing.
However, a good editor is recommended. For example, you can match brackets with the % command in vi, or if you have a color editor, you can visually see what's going on. A better IDE would even allow you to hide/show blocks of code, format it with proper indentation, and flag any compilation issues from static rules without actually compiling your code.
I'm using PC-Lint to lint a C project. I want to ignore errors and warnings in third party libraries, but I'm not able to get this. Reading the manual, I check all #include files specified with angle brackets are considered as libraries.
[...] and you want this header to be regarded as a library header use angle brackets
as in: #include <\include\graph.h>
Or for example, using the -libh command to indicate that header file is a library.
Using the option -vf, I've verified that my library files are being included as libraries. So everithing is OK.
The problems is that I'm receiving lot of errors from these files. I thought that since these files are considered as libraries, errors would be ignored.
How can ignore errors in library files? I've tried with -wlib(0), but this option ignore errors in header files too. In addition, generates an umcofortable warning:
Warning 686: Option '-wlib(0)' is suspicious because
of 'the likelihood of causing meaningless output'; receiving a syntax error
in a library file most likely means something is wrong with your Lint
confinguration
Any suggestion? Thanks in advance
I had to read several times the PC-Lint manual and check the output log several times. The "problem" is by default the expression
+libclass(angle, foreign)
is enabled, so all .h files are considered libraries. It is necessary to overwrite this expression by using:
+libclass(angle)
In order to treat these files as headers an not libraries.
Thanks again.
Sorry for posting late but I found this thread when looking for ways to remove the -wlib(0) warning in the output.
So for others looking for that answer a simple -e686 before the -wlib(0) removes that warning from the output.
I understand this does not answer the original question, but sometimes this is what you want to do.
In my project the definitions.h file with some definitions has been changed.
As a result a thousands of compiler erros appeared.
The definitions.h contains the definitions of thousands structs and types, but only a small part of them is relevant to my code.
I want to systemize the errors log file and find which structures are relevant.
For example structure a.b.c has been changed to d.f.g.
I want some tool or script to find all place it causes an error.
To be clear, i want from the list of thousand compiler erros obtain a small (50-100) list of similar errors.
Thanks, Mark
you cannot argue with compilers. If it says there are thousands of errors you have to resolve them (if you don't want to change compilation flags). You can print the output to a file and go through them.
I don't think that this is possible in general. Think about it logically: if it were feasible for a tool to "collapse" many errors into a single error where they all share the same root cause, then your compiler would already be doing it for you.
I'm working on some code where a great deal of the variables are named abc1, abc2, abc3, etc. I'm wondering if anyone knows if it's possible to check if the variable has been set so I can loop through a group of them easily, e.g.
do lbl1 i = 1,100
IF (.NOT. NULL(abc&i)) THEN
print*, abc&i
END IF
lbl1..continue
Any info would be great, thanks very much.
There is no way to do this from within Fortran: there is no intrinsic to check that a variable has been defined (other than NULL() and that only works for pointers). You have three real options here:
Get the compiler to complain about the use of undefined variables at compile time. I cannot think of a compiler which does not do this if you turn on its standard warnings. For example, g95 will say "Warning (113): Variable 'a' at (1) is used but not set" when used with -Wall but will just produce code which produces random rubbish if not. The problem with this approach is that not all such cases can be caught at compile time - think about passing an undefined variable into a subroutine when you compile the two procedures separately before linking.
Make all variables "invalid" and check for this in the program. One way would be to do this by hand (in the code) but Pete's second approach using a compiler flag is better. This is easer with reals than integers because you can set the invalid value of an undefined variable to NaN which should cause the executable to stop running (and give a useful backtrace) if it's used without being defined. For g95 -freal=NaN and -fpointer=invalid are useful, -finteger=-9999 may help but probably will not give quite as helpful debugging info.
Do the checks at runtime by monitoring how the executable is accessing memory. I've had success with Valgrind's memcheck. All you need to do is compile the code with debugging flags (-g or whatever) and run your program via valgrind with --undef-value-errors=yes --track-origins=yes and you should get a useful report of which variables were used undefined with backtraces for each case. This will be quite slow (all memory access gets tracked and a bitmap of status updated) but it does work, even for Fortran.
In practice 1 and 2 can be combined to catch most cases - and you really want most cases sorted out before trying to wade a massive valgrind output looking for the difficult cases.
I can think of two related options:
When the program starts up, set all of these variables to an invalid value (-9999). Check the value at run-time.
Some compilers have flags to do just this. For example, the IBM compiler lets you initialize to a specific hex value:
-qinitauto=<hex_value> | -qnoinitauto
Initializes each byte or word of storage for
automatic variables to the specified hexadecimal
value <hex_value>. This generates extra code and
should only be used for error determination.
Default: -qnoinitauto
However, as the man page says, "This generates extra code and should only be used for error determination."