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

[OT] Re: preprocessor/linker c++ error



ccostin  writes:

> What's wrong with the followind C++ code ?
> $ cat file1.cc
> #include "file.hh"

int a, b, c;

> void f1(int x,int y, int z)
> {
>        a=x;
>        b=y;
>        c=z;
> }

> $ cat file2.cc
> #include "file.hh"
> void f2(int x,int y, int z)
> {
>        a=x;
>        b=y;
>        c=z;
> }

OK.

> $ cat file.hh
> #ifndef _FIS_H_
> #define _FIS_H_
> int a,b,c;

extern int a, b, c;

> void f1(int x,int y, int z);
> void f2(int x,int y, int z);
> #endif

> $ cat mult.cc
> #include <stdio.h>
> #include "file.hh"

> int main(int argc, char **argv)
> {
>        f1(2,4,5);
>        f2(-4,-6,-7);
> }

> At compilation some unexepected errors appear:

> g++ -g3 -Wall mult.cc file1.cc file2.cc file.hh  -o mult

$  g++ -g3 -Wall mult.cc file1.cc file2.cc -o mult; ls -altr mult
-rwxr-xr-x 1 jtocancipa jtocancipa 30690 2007-02-19 20:30 mult

> Same files, in C variant (using .c and .h file extensions) are
> compiled (using gcc) without any error or warning.

BTW why are you trying to use the C++ compiler if your code doesn't
use classes at all but looks like pure C code?

-- 
--Jhair



Reply to: