I'm trying to compile source code, that from 2001, in Ubuntu 18.04.2 LTS. But, I got the errors below and actually don't know how I have to change the compiling code. Can you help me for compiling this code?
Suggested compilation part from the program
SUGGESTED COMPILATION COMMAND LINE (FOR A DEC-ALPHA CC-COMPILER):
cc -lm -fast -tune host -arch host -assume whole_program \
-o mol_volume mol_volume.c
When I tried this code, errors;
cc: error: host: No such file or directory
cc: error: host: No such file or directory
cc: error: whole_program: No such file or directory
cc: error: unrecognized command line option ‘-fast’; did you mean ‘-Ofast’?
cc: error: unrecognized command line option ‘-tune’; did you mean ‘-mtune=’?
cc: error: unrecognized command line option ‘-arch’; did you mean ‘-march=’?
cc: error: unrecognized command line option ‘-assume’; did you mean ‘-msse’?
Then, I changed -fast, -tune, -arch, -assume flags with -Ofast, -mtune=native, -march=native, -msse then add the path the for the directory part of the errors.
cc -lm -Ofast -mtune=native -march=native -msse /mypath/ -o mol_volume mol_volume.c
Then, I got that error;
mol_volume.c: In function ‘main’:
mol_volume.c:235:10: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
while( gets(s) ) {
^~~~
fgets
mol_volume.c:311:26: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
printf("WARNING: the %i-th atom of the pdb file %s has an unknown chemical type %s.\n",
~^
%li
i+1, pdb_name, atom_type);
~~~
/usr/bin/ld: cannot find .: File format not recognized
collect2: error: ld returned 1 exit status
You can access the source code via this link;
Source Code
My PC info:
Operation System: Ubuntu 18.04.2 LTS
Kernel ver.: 4.15.0-50-generic
GCC ver.: 7.4.0
gets was removed in C11. Compile with gcc -o mol_volume -Wall -std=c99 -mtune=native -O3 mol_volume.c -lm.
It will work but you should fix the code to remove all the warnings.
Related
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
When I want to compile this sample code with gcc aa.c -o tt I get an error:
/usr/bin/ld: 1: Syntax error: ")" unexpected
collect2: error: ld returned 2 exit status
I got this error when making a repo to install and I got the below error in the log file (a portion of the file).
gcc version 7.5.0 (Ubuntu 7.5.0-6ubuntu2)
configure:3674: $? = 0
configure:3663: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3674: $? = 1
configure:3663: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'; did you mean '--version'?
gcc: fatal error: no input files
compilation terminated.
configure:3674: $? = 1
configure:3694: checking whether the C compiler works
configure:3716: gcc conftest.c >&5
/usr/bin/ld: 1: Syntax error: ")" unexpected
collect2: error: ld returned 2 exit status
configure:3720: $? = 1
I am getting this error each time and i do not not what is happening .. can anyone help please ?
#Mike Kinghan this is the new error
08:21:40 **** Incremental Build of configuration Debug for project 5exe ****
make all
Building file: ../5exe.c
Invoking: GCC C Compiler
gcc -I"C:\Users\Dylan Galea\workspace\5\source" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"5exe.d" -MT"5exe.o" -o "5exe.o" "../5exe.c"
../5exe.c: In function 'main':
../5exe.c:42:10: warning: variable 'temp' set but not used [-Wunused-but-set-variable]
char temp; //temporary storage to remove the extra ( character
^
Finished building: ../5exe.c
Building target: 5exe.exe
Invoking: MinGW C Linker
gcc -L"C:\Users\Dylan Galea\workspace\5\Debug -o "5exe.exe" ./5exe.o -l5
/usr/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/usr/bin/sh: -c: line 1: syntax error: unexpected end of file
makefile:29: recipe for target '5exe.exe' failed
make: *** [5exe.exe] Error 258
08:21:40 Build Finished (took 463ms)
Your source code (which you didn't post) has an unterminated string literal, something like
printf("example text %d with an integer , 4);
/* ^ missing `"' /*
The backslash ('\') is an escape-character for the shell (/usr/bin/sh). So in this line:
gcc -I"C:\Users\Dylan Galea\workspace\5\source\" -O0 -g3 -Wall -c -fmessage- length=0 -MMD -MP -MF"5exe.d" -MT"5exe.o" -o "5exe.o" "../5exe.c"
the backslash '\' that follows source escapes the following ", and the string
"C:\Users\Dylan Galea\workspace\5\source\" is parsed as having unbalanced quotes.
Do one of the following:
Escape the backslashes:-
-I"C:\\Users\\Dylan Galea\\workspace\\5\\source\\"
Replace them with forward slashes:
-I"C:/Users/Dylan Galea/workspace/5/source/"
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?
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).
I am working on a malloc lab program where i need to find the performance index of utility and throughput. I am able to get the output efficiency but there is one problem when executing for the first time.
I have given specific set of files which includes traces and other files,When i am trying to run the program first time it is showing errors but when i run the same code with same command second time to multiple times i am not getting error and output is fine? why it is showing error in when running first time ? is there any problem with allocating memory or performing operation in malloc ?
the commands and first time error as follows ,
enter code here
#ubuntu:$ make
when i run this first time i am getting error which is as follows ,
enter code here
gcc -Wall -O2 -m32 -c -o mdriver.o mdriver.c
mdriver.c: In function ‘remove_range’:
mdriver.c:438:9: warning: variable ‘size’ set but not used [-Wunused-but-set-variable]
int size;
^
mdriver.c: In function ‘read_trace’:
mdriver.c:498:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->sugg_heapsize)); /* not used */
^
mdriver.c:499:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->num_ids));
^
mdriver.c:500:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->num_ops));
^
mdriver.c:501:11: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%d", &(trace->weight)); /* not used */
^
mdriver.c:524:12: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%u %u", &index, &size);
^
mdriver.c:531:12: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%u %u", &index, &size);
^
mdriver.c:538:12: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(tracefile, "%ud", &index);
^
gcc -Wall -O2 -m32 -c -o mm.o mm.c
mm.c:780:13: warning: ‘mm_check’ defined but not used [-Wunused-function]
static int mm_check(void)
^
gcc -Wall -O2 -m32 -c -o memlib.o memlib.c
gcc -Wall -O2 -m32 -c -o fsecs.o fsecs.c
gcc -Wall -O2 -m32 -c -o fcyc.o fcyc.c
gcc -Wall -O2 -m32 -c -o clock.o clock.c
gcc -Wall -O2 -m32 -c -o ftimer.o ftimer.c
gcc -Wall -O2 -m32 -o mdriver mdriver.o mm.o memlib.o fsecs.o fcyc.o clock.o ftimer.o
I run the same command again
enter code here
#ubuntu:$ make
make: `mdriver' is up to date.
Now then it shows no error and after that if i run the program with the required commands it works perfectly fine ,but it is showing errors first time ?
There is no error in your source. There are many warnings. The object and executable files will be generated even source is having warnings. In makefile, the files will not be recompiled if the timestamp is remains same.
For more understanding, tiger some compilation error in your source and run make command again and again then you can understand the difference.