Re: g++ compiler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux