Compiling a project with '-ansi'

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Compiling a project with '-ansi'

Niccolo Medici
In a project I'm writing I want to ensure my C code doesn't use
newfangled features, so I compile it with `-ansi` (or `-std=c90`). I'm
using gcc.

However, in this mode the compiler emits an error:

    /usr/include/lua5.3/luaconf.h:573:2:
    error: #error "Compiler does not support 'long long'. Use option
'-DLUA_32BITS'
    or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"

What should I do?

The Lua library on my system (liblua5.3.so) is precompiled with 64
bits integers. I don't want to ship Lua together with my project. So I
want Lua's header files to define integers as 64 bits (to match the
installed Lua library). But if I add '-DLUA_32BITS' or
'-DLUA_C89_NUMBERS' to my CFLAGS, as the error message advises,
there'd be a mismatch between the Lua headers and my system's
liblua5.3.so.

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a project with '-ansi'

Luiz Henrique de Figueiredo
> In a project I'm writing I want to ensure my C code doesn't use
> newfangled features, so I compile it with `-ansi` (or `-std=c90`). I'm
> using gcc.
>
> However, in this mode the compiler emits an error:

Unfortunately, there is no way around this. The Lua C API uses lua_Integer and so lua_Integer in your code must be the same as lua_Integer in the installed Lua library.

I sympathize: Most of my Lua libraries are written in C90 but when Lua 5.3 came out I had to remove -ansi from the Makefiles and use -std=c99.

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a project with '-ansi'

Roberto Ierusalimschy
In reply to this post by Niccolo Medici
> In a project I'm writing I want to ensure my C code doesn't use
> newfangled features, so I compile it with `-ansi` (or `-std=c90`). I'm
> using gcc.
>
> However, in this mode the compiler emits an error:
>
>     /usr/include/lua5.3/luaconf.h:573:2:
>     error: #error "Compiler does not support 'long long'. Use option
> '-DLUA_32BITS'
>     or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
>
> What should I do?
>
> The Lua library on my system (liblua5.3.so) is precompiled with 64
> bits integers. I don't want to ship Lua together with my project. So I
> want Lua's header files to define integers as 64 bits (to match the
> installed Lua library). But if I add '-DLUA_32BITS' or
> '-DLUA_C89_NUMBERS' to my CFLAGS, as the error message advises,
> there'd be a mismatch between the Lua headers and my system's
> liblua5.3.so.

You may try the options '-ansi -Wno-long-long'. (It seems strange that a
'-W' affects definitions in the program, but it worked in my system.)

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a project with '-ansi'

Sam Putman
In reply to this post by Niccolo Medici


On Wed, Aug 31, 2016 at 9:29 AM, Niccolo Medici <[hidden email]> wrote:
In a project I'm writing I want to ensure my C code doesn't use
newfangled features, so I compile it with `-ansi` (or `-std=c90`). I'm
using gcc.

However, in this mode the compiler emits an error:

    /usr/include/lua5.3/luaconf.h:573:2:
    error: #error "Compiler does not support 'long long'. Use option
'-DLUA_32BITS'
    or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"

What should I do?


One possibility is to use, instead of -ansi, the flag -Wc90-c99-compat

This will issue warnings rather than errors for newfangledness.  

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a project with '-ansi'

Niccolo Medici
On 9/1/16, Sam Putman <[hidden email]> wrote:

> On Wed, Aug 31, 2016 at 9:29 AM, Niccolo Medici <[hidden email]>
> wrote:
>
>> In a project I'm writing I want to ensure my C code doesn't use
>> newfangled features, so I compile it with `-ansi` (or `-std=c90`). I'm
>> using gcc.
>>
>> However, in this mode the compiler emits an error:
>>
>>     /usr/include/lua5.3/luaconf.h:573:2:
>>     error: #error "Compiler does not support 'long long'. Use option
>> '-DLUA_32BITS'
>>     or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
>>
>> What should I do?
>>
>
> One possibility is to use, instead of -ansi, the flag -Wc90-c99-compat
>
> This will issue warnings rather than errors for newfangledness.

Thanks for the advise!

I ended up using "-Wc90-c99-compat -Wno-long-long".

Here are my findings:

0. The problem pertains to Lua 5.3 only. (Earlier ones don't support
integers, so the "long long" issue doesn't exist there, IIUC.)

1. We can't use -ansi (or -std=c90) because this eventually triggers
the #error line in 'luaconf.h'. At least in the stock Lua package that
comes with Ubuntu.

2. So instead we have to use warnings: -Wc90-c99-compat.

2.a. Unfortunately, while the -Wc90-c99-compat switch exists in gcc, I
don't know of equivalent clang switch.

3. We also need to add -Wno-long-long so that the Lua headers work.

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a project with '-ansi'

Liam Devine

> Thanks for the advise!
>
> I ended up using "-Wc90-c99-compat -Wno-long-long".
>
> Here are my findings:
>
> 0. The problem pertains to Lua 5.3 only. (Earlier ones don't support
> integers, so the "long long" issue doesn't exist there, IIUC.)
>
> 1. We can't use -ansi (or -std=c90) because this eventually triggers
> the #error line in 'luaconf.h'. At least in the stock Lua package that
> comes with Ubuntu.
>
> 2. So instead we have to use warnings: -Wc90-c99-compat.
>
> 2.a. Unfortunately, while the -Wc90-c99-compat switch exists in gcc, I
> don't know of equivalent clang switch.
>
> 3. We also need to add -Wno-long-long so that the Lua headers work.
>
As an alternative, both clang and gcc accept the "__extension__" prefix
where long long is valid. The more correct way, is to check for the
presence and the values of a concoction of POSIX macros and then use
int64_t.

--
Liam