gcc4.5 on redhat enterprise 3 wield asm warning message - c

I compiled gcc 4.5.2 on a 64bit Redhat enterprise 3 machine (2.4.21-20.ELsmp, glibc 2.3.2). It compiles ok but with a lot of warning message like
/tmp/ccbGRF5F.s: Assembler messages:
/tmp/ccbGRF5F.s:29: Warning: rest of line ignored; first ignored character is `d'
/tmp/ccbGRF5F.s:33: Warning: rest of line ignored; first ignored character is `d'
/tmp/ccbGRF5F.s:169: Warning: rest of line ignored; first ignored character is `i'
Then I try to compile code with the compiler, still it spits these asm warnings, and I'm not using any asm in my C code. How can I get rid of it? Fix or suppress warning are all fine.

It seems your binutils is too old to handle gcc-4.5's output - and in another project it might outright end in a compile failure. Given RHEL3, that would not surprise me at all.

I'm assuming you're using the command line to compile? adding a "-w" flag to the compile command will suppress all warnings. For example, to compile hello.c without warnings:
gcc hello.c -w -o hello
Will produce the output file "hello", without spitting out any errors.

Related

Compilinig error on WSL when I try to compile a C sourcefile with command line parameters

The compiler fails when compiling the C code below, throwing stray character errors:
#include "stdio.h"  
int main(int argc, char *argv[]) {
     int count;  
     printf("The command line has %d arguments:\n", argc - 1);  
     for(count = 1; count < argc; count++) {  
       printf("%d: %s\n", count, argv[count]);  
      }  
      printf("\n");  
 
      return 0;  
}
Compiler: gcc 5.4.0 20160609 Ubuntu 16.04.3
Screenshot of the error: here
By the way, other C files (like "hello world") can be successfully compiled.
Continuing from my comment, "There are no errors in your code", so any error you receive is either due to your compile string OR is due to you having edited the file in a windows editor that has corrupted the file within WSL.
To compile your code (without warning or error) to the default a.out executable, you can use a simple command line of:
gcc -Wall -Wextra yourfilename.c
note: always compile with warnings enabled, at minimum -Wall -Wextra. You can add many more individual warning options as well as adding -pedantic which will enable a few more.
If you want to add a few additional options, the optimization level and the C-standard to compile against, as well as providing a custom name for your executable instead of the default a.out, you can use:
gcc -Wall -Wextra -pedantic -std=gnu11 -O3 -o yourexename yourfilename.c
Give both a try and report back with the exact error (if any) you receive by editing your question and adding the exact text of the error you receive to your question.
Let me know if you have any further questions.

Gcc do not give warning about newline of end of file

I tried to code a well known hello world program in c and compiled it using this command :
gcc -Wall -Wextra -pedantic -std=c99 main.c -o exeFile
but I did not get any warning about 5.1.1.2 in C standard (newline at end of file).
I used Vim editor for that and I has also disabled newline settings by typing:
set binary
set noeol
I want to know how can I generate this warning.
used GCC: 5.4.0
This is the source file :
This is the output of compiler:
This was a deliberate decision made in the GCC 4.3.2 timeframe, and carried forward to subsequent releases:
WONTFIX Bug 40474 - gcc 4.3 no longer warns about missing newlines at end of files
RESOLVED Bug 14331 - please add option to suppress warning message "no newline at end of file"

Please help me to compile this C program? [Linux]

I am using Linux now, and trying to compile this by gcc BUT.......
this is my truly simple code:
#include <stdio.h>
int main(){
printf("Hello world\n");
return 0;
}
and this is so much weird output:
./try.c: line 3: syntax error near unexpected token `('
./try.c: line 3: `int main(){'
why is it?
I have tried the right way to compile it, such:
gcc file_name.c -o file_name and other types of way of compiling
chmod +rwx file_name.c
./file_name.c
but still I got that result, why?
You have to compile the code first.
Follow these steps.
gcc try.c -o try.out
to compile the code. The -o option is given to give a custom name to the executable that will be produced.
Then, you can run it by typing
./try.out
To run the executable.
Be informed though, that there are a number of command line options that you can use to get the information about your code and add more functionality. See this page for more information.
You are trying to execute the .c file, remove the trailing .c from the name of the file you want to execute.
Like this:
gcc -Wall -Wextra -pedantic -Werror -o executable file_name.c
You should not need to make it executable, it should already be executable since the compiler will do that.
./executable
As you see, I've passed some parameters to gcc to let it help in diagnosing problems, sometimes these problems are caused by your lack of knowledge and some other times because you write code quickly and miss some details. So using them is good (although compilation is slower, but that doesn't matter if you have a good and fast machine, wehreas having issues in the code does matter).
The meaning of these flags are as follows
-Wall Enable all warnings. Really some are not enabled, but most are.
-Wextra Enable extra warnings.
-pedantic make the compiler pedantic, i.e. stick strictly to the desired (default for this version of gcc) standard.
-Werror Consider that warnings are errors.
Also, you could have guessed this if you see what the error says
./try.c: line 3: syntax error near unexpected token `('
./try.c: line 3: `int main(){'
as you can see the shell is trying to execute the source code as if it was a shell script, so you can immediately notice that this is not the executable file generated by gcc, and then you would notice the .c in the file name.
Try
gcc try.c
./a.out
Compiles the code and runs it. Please read the manual page for gcc and there are many delights to behold (extra checking etc)

Warnings while compiling a C library

I am trying to compile a C library and I am getting a loy of warning while doing it. Though the compiled library is working properly, I am still a bit apprehensive about the warnings. I googled all the warnings, but the relevant search results are hard to come by.
The warnings are:
main(){printf("osx%d", (int) (sizeof(void *)*8));}
^~~~
1 warning generated.
clang: warning: argument unused during compilation: '-s'
This warning is in the shell script that I used to compile the libraries. Could someone tell me what the -'s' flag is and how I can remove this warning?
Next warning:
warning: unknown warning option '-Wno-long-double'; did you mean '-Wno-long-long'? [-Wunknown-warning-option]
and the next one,
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: fortify.o has no symbols
clang: warning: argument unused during compilation: '-s'
Anyway to silence these warning?
Look at the manual of gcc for details of what each option should do.
AFAICT, clang not accepting those flags does not lead to any failure of the built executable.
Excerpt:
-s: Remove all symbol table and relocation information from the executable. (linker)
-Wno-long-double: Looks like someone wants to disable use of long double. Cannot find it for newest GCC. Chances are the code does not contain such anyway.

How to compile a Linux kernel module using -std=gnu99?

I've recently learned how to program simple character drivers and while playing around with the code I noticed that I get a lot of the following GCC warnings thrown for my C99 code:
warning: ISO C90 forbids mixed declarations and code
I assume this is because the main Linux kernel Makefile is set to compile using a non-C99 standard. I searched around I found this answer here on stackoverflow: How to use make and compile as C99?
So I naturally tried the following in my Makefile:
ccflags-y := -std=gnu99
Unfortunately this didn't silence the GCC warnings. I checked the verbose output of make and verified that GCC is indeed executed with the -std=gnu99 tacked on at the end; so I'm a bit confused.
How do I properly compile a Linux kernel module using the -std=gnu99 option?
EDIT:
I noticed the GCC output shows this option: -Wdeclaration-after-statement. Is this why I am getting the warnings even with the -std=gnu99 option?
It turns out that -std=gnu99 does in fact work; I began seeing errors regarding C99 features after removing the compiler flag. So that meant something else was causing the warnings to print out besides the -std= option.
After parsing through the verbose output via make V=1, I discovered the -Wdeclaration-after-statement option as part of the GCC execution. This was the cause of the ISO C90 mixed declaration warnings I saw.
To disable the ISO C90 warnings, pass this to GCC: -Wno-declaration-after-statement.
For example:
ccflags-y := -std=gnu99 -Wno-declaration-after-statement
You can also specify the flag in your Makefile, if you have one:
FLAGS=-std=gnu99

Resources