[cfe-dev] Compiling BRL-CAD with clang/clang++

Chris Lattner clattner at apple.com
Sat Nov 20 16:17:45 PST 2010


On Nov 20, 2010, at 3:51 PM, Clifford Yapp wrote:

> Hi - not sure if I'm in the right mailing list for these questions,
> but I'm trying to build BRL-CAD (http://brlcad.org) with clang/clang++
> and running into a few things that have me guessing.  I'm not sure if
> they are bugs or the fault of our own code (we do build successfully
> with gcc), and any advice would be appreciated (I'm happy to file bug
> reports but I don't want to waste time with things that aren't issues)
> 
> 1)  When building with clang/clang++ and using the default ld linker,
> we get failures to link on code like the following:
> 
> HIDDEN inline int
> fnalnum(int c)
> {
>    return isalnum(c);
> }
> 
> Removing the inline allows things to succeed, as does using llvm-ld
> instead of ld - is this know/expected?

This is almost certainly because clang defaults to C99 mode, and your code is only valid in C89.  I'd suggest changing that function to be "static inline".  More info here:
http://clang.llvm.org/compatibility.html#inline


I don't know about the other issue off-hand.

-Chris


> 
> 
> 2)  We are getting the following error:
> 
> sh_prj.c:409:41: error: initializer element is not a compile-time
>      constant
> struct bu_structparse img_print_tab[] = {
> 
> on this bit of code:
> 
> struct bu_structparse img_print_tab[] = {
>    {"%p",      bu_byteoffset(img_parse_tab[0]), "img_parse_tab", 0,
> BU_STRUCTPARSE_FUNC_NULL },
>    {"%f",      4, "i_plane",           IMG_AO(i_plane),
> BU_STRUCTPARSE_FUNC_NULL},
>    {"",        0, (char *)0,           0,
> BU_STRUCTPARSE_FUNC_NULL}
> };
> 
> the offending bu_byteoffset is (if I've walked through all the if
> defined stuff right)
> 
> #define bu_byteoffset(_i)     ((size_t)((char *)&(_i)))
> 
> (full code for bu_byteoffset is defined in this file:
> http://brlcad.svn.sourceforge.net/viewvc/brlcad/brlcad/trunk/include/bu.h?revision=41330)
> 
> This does work with gcc without complaining about compile-time
> constantness - is there something new/specific to clang that forbids
> this setup?
> 
> Any help appreciated.
> 
> CY
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list