Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Sometimes gcc displays a single error/warning message in several lines.
Not a big deal, but it looks a little strange (and ugly) to me.
server_inc.c: In function ‘prepareForConn’:
server_inc.c:101: error: ‘filename’ undeclared (first use in this function)
server_inc.c:101: error: (Each undeclared identifier is reported only once
server_inc.c:101: error: for each function it appears in.)
Specially because the location (server_inc.c:101: error:) is prepended, so it looks as if there were many errors.
Is there some way to change this? I'm using gcc 4.4.7 on Linux.
Starting with GCC 4.5, the second message appears on a single line, and is prepended by "note" rather than "error":
$ cat test.c
int main() { x=3; }
$ gcc-4.5.4 -c test.c
test.c: In function ‘main’:
test.c:1:14: error: ‘x’ undeclared (first use in this function)
test.c:1:14: note: each undeclared identifier is reported only once for each function it appears in
With GCC 4.4, I can reproduce the behaviour you're seeing, and that does look like a bug without any way to work around it. If possible, please upgrade your compiler.
Probably because default terminal size has a historical width of 80 columns, see this question.
Given this, GCC has a behavior which by default could follow this rule, taken from here:
-fmessage-length=n
Try to format error messages so that they fit on lines of about n characters. The default is 72 characters for g++ and 0 for the rest of the front ends supported by GCC. If n is zero, then no line-wrapping is done; each error message appears on a single line.
You could specify -fmessage-length=0 to remove line wrapping.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to build a big project step by step. I'm working on Linux and using qt-creator and gcc compiler. I include a set of related files in the .pri file and then build, test functionality and then add a new set of existing files and so on.
The project compiled successfully then I included a folder containing some header files then when compiled I got many errors in libc-header-start.h, string.h, cpu-set.h, time.h and many other stdlib and system files. Errors like missing binary operator before token (, unknown type name __cpu_mask, expected ';', ',' or ')' before '*' token.
I think these are likely to be preprocessor errors that are caused, for example, if I forget a semicolumn or so, right?
My question is, how can I locate the exact location in the header/source files where all these errors started, for example, the line of code where the semicolumn is missing.
This answer is just collecting the comments on my question.
Here is what can help locating what is the root cause of preprocessor errors:
Make sure that the names of your header files don't conflict with standard header files.
Check the first file in the errors list. Check where this file is included. If this file is included by another standard header file, check where the parent header file is included in your code. The root cause of the errors may be in the lines before that #include statement in your code. For example, you may have forgetten a semi-column before this #include.
Use gcc -H file.c to check all the header files included with file.c.
Use gcc -E file.c to generate a preprocessed version of file.c, then you will have the full end picture of your file which you can then investigate.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Picture of code
I have a problem with clang 7 error, I don't know what the issue is? Why is clang -o hello hello.c not working? I have already tried twice and the error repeated itself so I am unsure why the clang -o hello hello.c is not working.
Read the messages. The clang command told you:
/usr/bin/ld: cannot open output file hello: Is a directory
The “/usr/bin/ld:” part says the specific program “/usr/bin/ld” (which is the linker; it links object files into an executable file) is giving you this message.
The “cannot open output file hello” part says it cannot output the file named “hello”.
The “Is a directory” part says why there is a problem: “hello” is a directory, meaning it exists and is a directory, not a regular file, so it cannot be opened like a regular file. The linker wants to open it as a regular file so that it can write to it.
To fix this, either remove or rename the directory named “hello” (check what is in it first, to see if you want it) or use a different output file name in the clang command.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I was trying to install TensorFlow for C on Ubuntu. I followed all instructions in the page : https://www.tensorflow.org/install/install_c
Please see the commands and results below. Please let me know why I am getting compilation error:
hadoopuser#sarkar-D900C:/home/sarkar/tensorflow$ gcc hello_tf.c
hello_tf.c: In function ‘main’:
hello_tf.c:5:3: error: stray ‘\342’ in program
printf(“Tensor flow C library version %s\n”,TF_Version());
^
hello_tf.c:5:3: error: stray ‘\200’ in program
hello_tf.c:5:3: error: stray ‘\234’ in program
hello_tf.c:5:13: error:‘Tensor’ undeclared (first use in thisfunction)
printf(“Tensor flow C library version %s\n”,TF_Version());
^
hello_tf.c:5:13: note: each undeclared identifier is reported only
once for each function it appears in
hello_tf.c:5:20: error: expected ‘)’ before ‘flow’
printf(“Tensor flow C library version %s\n”,TF_Version());
^
hello_tf.c:5:20: error: stray ‘\’ in program
hello_tf.c:5:20: error: stray ‘\342’ in program
Thanks,
S Sarkar
After some research I found this: gcc stray errors
The reason for the errors are the quotation marks. A possible fix would be to replace them.
Best regards.
Just change all the “ with ".
This question already has answers here:
how does url within function body get compiled
(2 answers)
Closed 6 years ago.
I found I added some URL in source code but forgot to comment it, but still can compile, and I test it individually:
int main(){
http://localhost
return 0;
}
gcc hello.c -o hello.exe
Which can still compile without errors, and I check c keywords, 'http' seems not a keyword, what is the reason?
Because it'll be treated as a label followed by a comment.
So you could later:
goto http;
If you turn on warnings: -Wall it'll warn you gracefully:
In function ‘main’:
:2:5: warning: label ‘http’ defined but not used [-Wunused-label]
http://localhost
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have created a a simple file under one work area, build it and executed successfully. And again created another file under same work area. I am getting linking error like:
"====Linking===== Error: Duplicate public_main in module...." while building and I am getting the same error when I try to execute first file also.
Please see the below code and suggest.
File1: n_numbers.c
#define N 10
main()
{
int count;
float sum, number;
count=0;
sum=0;
printf("Enter 10 numbers to calculate the Sum");
while(N<10)
{
scanf("%f", &number);
sum=sum+number;
count=count+1;
}
printf("sum=5.2%", sum);
}
File2: two.numbers.c
main()
{
int a,b,c;
printf("Enter Two numbers for a and b\n");
scanf("%d %d",&a, &b);
c=a+b;
printf("c=%d", c);
}
I suspect your problem is:
gcc file_a.c
a.out
Works
gcc file_b.c
a.out
Works
gcc file_a.c file_b.c
linker error
Will be because gcc is trying to make a single executable and each executable must have exactly one main function.
If file_a and file_b both define a function called public_main the problem becomes which one is intended in any given invocation - C solves this by a simple rule - you can only have one of each function in each executable.
N.B. Other languages have different rules, C++ can have multiple functions with the same name but different prototypes, (overloading), or within different classes, (namespaces), it actually does both via what is called name mangling. Python uses namespaces and sophisticated scoping rules, etc.
Copied from comments!
Hi Steve, I had only one main() in each executable, but still i am
getting same error – user2714972
You have 2 .c files and you are linking them into a single executable,
(.exe), that is what gcc does when you give it more than one .c file
if you would like to make 2 executables you need to call gcc twice,
once with each .c and with -o differcent_exe_name to stop both being
called a.out or a.exe – Steve Barnes
If, as some have suggested, you are using an IDE you need to either create separate projects or specify separate targets depending on the IDE.