This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: g++ compiler
Hi,
> please help me
> how to compiling this main with GCC, the GNU Compiler
> i use g++ -pthread -Wall main.cpp
> but don't pass argument
The compiler is right - your file is wrong;-)
>
> main.cpp
> int main(int argc, char *argv[]) {
> /* Verify the correct number of arguments were passed in */
> if(argc != 4) {
> fprintf(stderr, "USAGE:./main.out <INT> <INT> <INT>\n");
> }
> int mainSleepTime = atoi(argv[1]);
> int numProd = atoi(argv[2]);
> int numCons = atoi(argv[3]);
> exit(0);
> }
If you save the file with extension "cpp", GCC will treat it as a C++
code. However, in C++ you have to declare all functions before you use
them (e.g. atoi, exit, fprintf) and also all constants or variables
(like "stderr").
These are declared in header-files from the standard library - which you
have to include: So at the beginning of your file, you need
#include <cstdio>
#include <cstdlib>
with these two lines, the code should compile fine
HTH,
Axel