I'm trying to compile a C project with Eclipse, under Ubuntu 12.10 using GCC.
When I use these flags:
http://i.stack.imgur.com/FTxkG.jpg
http://i.stack.imgur.com/MVA2k.jpg
eclipse fails to compile.
The compilation error is the following:
error: ISO C forbids an empty translation unit [-pedantic]
make: *** [.metadata/.plugins/org.eclipse.cdt.make.core/specs.o] Error 1
Why do these problems appear,
and how should I compile with eclipse with the checked flags?
When trying to compile manually from the Terminal with these flags, it compiles successfully. thanks!
Your C project has an empty source file.
You can either:
1) Remove that file. If it is empty why do you need it?
2) Be more relax with your compilation flags, with -pedantic instead of -pedantic-errors for example
3) Add some dumb code to make gcc believe the file is not empty, for example add #include <stdio.h>.
Related
Trying to compile a c file that has the header:
#include <sys/wait.h>
I'm using Cygwin to compile it and it keeps giving me this error whenever I type in gcc minishell.c -o minishell:
minishell.c:4:22: fatal error: sys/wait.h: No such file or directory compilation terminated.
Any clue what the heck is going on?
That's because compiler, in this case, does not know how to reach/find sys/wait.h file so that it can include this file in compilation process. To check which all places compiler will try to find the files, refer:
How to tell C++ library path in Cygwin and MinGW
Above post/link also tells about include paths.
I get the following error when dealing with C using Fedora:
[king#localhost ~]$ gcc -o1 tempdaa.c
tempdaa.c:3:17: fatal error: queue: No such file or directory
#include <queue>
^
compilation terminated.
Any ideas on where the problem is?
gcc is generally what you use to compile C code. If you want to compile C++ code, you'd tend to use g++.
Now it's true that gcc can compile C++ if it's clear you have a C++ program but I think, from memory, that's indicated by the extension rather than the content.
Since your extension is .c rather than something like .cpp or .cc or .cxx, it will definitely think it's C code and behave accordingly.
Hence the C++ header queue will not be available to you.
My suggestion is that you name your C++ source files "correctly", or force the language type explicitly:
gcc -x c++ -o1 tempdaa.c
I want to compile a C code in ubuntu using mex which is configured with gcc. I can smoothly compile the code in OSX. However, when I want to compile it in Linux, the compiler generates the error on the comment lines starting with // (it works fine with /* */. Since the program includes several header files from third-party libraries, I cannot substitute // with /* */.
I would like to know whether there is any way around to overcome this problem.
MATLAB version: R2012b
gcc version in Linux: 4.7.2
gcc version in OSX: 4.2.1
Any help is appreciated
Edit:
Here is the command I use to compile the code:
mex -g -largeArrayDims -ldl TDSVDHNGateway.c
Here is the error generated by mex:
In file included from TDSVDHNGateway.c:2:0:
TDS.h:17:1: error: expected identifier or ‘(’ before ‘/’ token
TDS.h:26:2: error: unknown type name ‘index_t’
TDS.h:27:2: error: unknown type name ‘index_t’
In file included from TDSVDHNGateway.c:2:0:
TDS.h:146:3: error: unknown type name ‘index_t’
TDSVDHNGateway.c:37:3: error: unknown type name ‘index_t’
TDSVDHNGateway.c: In function ‘mexFunction’:
TDSVDHNGateway.c:166:25: error: ‘index_t’ undeclared (first use in this function)
TDSVDHNGateway.c:166:25: note: each undeclared identifier is reported only once for each function it appears in
Line 17 in header file is:
//Defining index_t
typedef size_t index_t;
If I replace //Defining index_t with /*Defining index_t*/ the code will be compiled with no problem.
From the gcc docs;
In GNU C, you may use C++ style comments, which start with ‘//’ and continue until the end of the line. Many other C implementations allow such comments, and they are included in the 1999 C standard. However, C++ style comments are not recognized if you specify an -std option specifying a version of ISO C before C99, or -ansi (equivalent to -std=c90).
Under Linux, by default mex adds -ansi, which disables C++ comments. Either update your mexopts file, replacing -ansi with -std=c99 or run mex with;
mex -g -largeArrayDims -ldl CFLAGS="\$CFLAGS -std=c99" TDSVDHNGateway.c
A weird behaviour when I shell:
bush#ubuntu:~/CPPWorkspace/Ex12$ gcc users/dubi/justPrnit.C
Returns an error:
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
But when I change justPrnit.C to justPrnit.c (with little 'c') it compiled successfully.
What's that?
error trying to exec 'cc1plus'
Because .C is assumed to be a C++ source file (cc1plus is the C++ parser backend of GCC - by the way, it seems that your local installation of GCC lacks g++ - are you using the default [incomplete] setup?).
To solve this, use the -x switch to force the language:
gcc -x c users/dubi/justPrnit.C
GCC recognises .C as C++, rather than C
I have written a simple C program using gcc compiler in Ubuntu enviroment. The code is simple. Howver, when i try to compile, it is giving an error which I am not able to fathom. Here is the code and the error
# include <stdio.h>
int main() {
enum mar_status {
single,married,divorced
};
enum mar_status person1,person2;
person1 = single;
printf("%d\n",person1); //line B
}
I am getting the following error when I compile
gcc enum2.cc
/tmp/cc6stgaW.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
If I remove the printf statement at line B, everything goes fine. Any ideas as to why the compilation is failing ?
You are using gcc to compile C++ code? (.cc extension)
Either rename the file to enum2.c or compile with g++.
Undefined references to internal run-time library functions, such as __gxx_personality_v0, are also a symptom of linking C++ object files with gcc instead of g++.
Changing file extension from .cc or .cpp to .c will resolve the issue.
You are confusing the compiler - when you say:
gcc enum2.cc
it thinks you are compiling C++ code, but you are doing it with gcc, which doesn't link the correct C++ libraries. Use:
gcc enum2.c
Its running fine. Check : http://ideone.com/bhjlf
I guess your command to compile is wrong.