[LLVMdev] Linking two external linkage GlobalValues

Ralph Corderoy ralph at inputplus.co.uk
Sat May 26 13:16:35 PDT 2007


Hi Anton,

> This is bug in the source code. You have two symbols with the same
> name in the different object files, which is definite redefinition. At
> least one of them should be declared with "extern".

C allows this.

    $ head foo.c bar.c
    ==> foo.c <==
    void bar();
    int foo;

    int main()
    {
        bar();
        return foo;
    }

    ==> bar.c <==
    int foo;

    void bar()
    {
        foo = 42;
        return;
    }
    $ gcc -Wall foo.c bar.c && ./a.out; echo $?
    42
    $

Better practice to have one definition I agree, but it's valid C.

Cheers,


Ralph.




More information about the llvm-dev mailing list