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
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
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.