Abhishek Kulkarni
2009-Dec-14 03:27 UTC
[LLVMdev] clang error: multiple definition of `gnu_dev_*'
When trying to link more than one object files compiled with clang, I run into
errors of the following type:
$ clang -fblocks -g -I$HOME/opt/include -L$HOME/opt/lib/ -o helloworld
helloworld.c hello.o world.o -lBlocksRuntime
world.o: In function `gnu_dev_major':
/usr/include/sys/sysmacros.h:43: multiple definition of `gnu_dev_major'
hello.o:/usr/include/sys/sysmacros.h:43: first defined here
world.o: In function `gnu_dev_minor':
/usr/include/sys/sysmacros.h:49: multiple definition of `gnu_dev_minor'
hello.o:/usr/include/sys/sysmacros.h:49: first defined here
world.o: In function `gnu_dev_makedev':
/usr/include/sys/sysmacros.h:55: multiple definition of `gnu_dev_makedev'
hello.o:/usr/include/sys/sysmacros.h:55: first defined here
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The platform I'm building this on is x86_64 GNU/Linux.
FWIW, here is how the source files look:
$ cat hello.c
#include <stdio.h>
#include <stdlib.h>
#include <Block.h>
void hello(void)
{
void (^a)(void) = ^{
printf("Hello");
};
a();
}
$ cat world.c
#include <stdio.h>
#include <stdlib.h>
#include <Block.h>
void world(void)
{
void (^a)(void) = ^{
printf("world");
};
a();
}
The error disappears if I take off one or both instances of the
"#include <stdlib.h>"
line.
Is this a clang issue?
Thanks,
Abhishek
Andrew Jeffery
2009-Dec-14 03:42 UTC
[LLVMdev] clang error: multiple definition of `gnu_dev_*'
On 14/12/09 13:57, Abhishek Kulkarni wrote:> When trying to link more than one object files compiled with clang, I run into > errors of the following type: > > $ clang -fblocks -g -I$HOME/opt/include -L$HOME/opt/lib/ -o helloworld > helloworld.c hello.o world.o -lBlocksRuntime > world.o: In function `gnu_dev_major': > /usr/include/sys/sysmacros.h:43: multiple definition of `gnu_dev_major' > hello.o:/usr/include/sys/sysmacros.h:43: first defined here > world.o: In function `gnu_dev_minor': > /usr/include/sys/sysmacros.h:49: multiple definition of `gnu_dev_minor' > hello.o:/usr/include/sys/sysmacros.h:49: first defined here > world.o: In function `gnu_dev_makedev': > /usr/include/sys/sysmacros.h:55: multiple definition of `gnu_dev_makedev' > hello.o:/usr/include/sys/sysmacros.h:55: first defined here > collect2: ld returned 1 exit status > clang: error: linker command failed with exit code 1 (use -v to see invocation) >I've recently been playing around with using Clang as the system compiler on a Gentoo system and found several packages that did something similar. The fix appears to be to add the -std=c89 option; from memory Clang defaults to c99 (while GCC defaults to c89) and there is a difference in the handling of inlining functions. One instance of this was also fixed by compiling Clang/LLVM from SVN, so if the c89 option doesn't fix it maybe give that a go (if you aren't already). Hope that helps, Andrew
Abhishek Kulkarni
2009-Dec-14 04:36 UTC
[LLVMdev] clang error: multiple definition of `gnu_dev_*'
On Sun, Dec 13, 2009 at 10:42 PM, Andrew Jeffery <andrew at aj.id.au> wrote:> On 14/12/09 13:57, Abhishek Kulkarni wrote: >> When trying to link more than one object files compiled with clang, I run into >> errors of the following type: >> >> $ clang -fblocks -g -I$HOME/opt/include -L$HOME/opt/lib/ -o helloworld >> helloworld.c hello.o world.o -lBlocksRuntime >> world.o: In function `gnu_dev_major': >> /usr/include/sys/sysmacros.h:43: multiple definition of `gnu_dev_major' >> hello.o:/usr/include/sys/sysmacros.h:43: first defined here >> world.o: In function `gnu_dev_minor': >> /usr/include/sys/sysmacros.h:49: multiple definition of `gnu_dev_minor' >> hello.o:/usr/include/sys/sysmacros.h:49: first defined here >> world.o: In function `gnu_dev_makedev': >> /usr/include/sys/sysmacros.h:55: multiple definition of `gnu_dev_makedev' >> hello.o:/usr/include/sys/sysmacros.h:55: first defined here >> collect2: ld returned 1 exit status >> clang: error: linker command failed with exit code 1 (use -v to see invocation) >> > > I've recently been playing around with using Clang as the system > compiler on a Gentoo system and found several packages that did > something similar. The fix appears to be to add the -std=c89 option;Thanks, that worked!> from memory Clang defaults to c99 (while GCC defaults to c89) and there > is a difference in the handling of inlining functions. One instance of > this was also fixed by compiling Clang/LLVM from SVN, so if the c89 > option doesn't fix it maybe give that a go (if you aren't already).Yes, I was compiling from the current trunk r91244.> > Hope that helps, > > Andrew > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >