[erlang-questions] rebar: how to set which C compiler to use

Tuncer Ayaz tuncer.ayaz@REDACTED
Fri Sep 4 11:40:32 CEST 2015


On Thu, Sep 3, 2015 at 3:15 PM, Ivan Uemlianin wrote:
> Dear All
>
> I have downloaded an erlang project which includes some C files, and
> which uses rebar as a build tool. I'd like to explicitly set which
> compiler rebar uses to compile the C files. Is this possible in the
> rebar.config?

If you don't want to use environment variables, you can configure
CC in rebar.config's {port_env, []}.

> Some details:
>
> - ./rebar compile returns a load of C compiler errors
> - adding CFLAGS and LDFLAGS helps a bit
> - Compiling C files individually I notice different C compilers have
> very different results. The platform this is all on "cc" is gcc 4.1,
> while "gcc" (which gets best results) is gcc 4.8.
> - rebar seems to be using "cc" (judging by the errors).

cc is used for portability, as not every platform has CC=gcc.
Therefore, default CC=cc and CXX=c++.

> - Setting a CC environment variable seems not to have any effect.

Are you sure about that?

$ env CC=ivancc rebar compile
[...]
sh: 1: exec: ivancc: not found

In addition to the usual CC, CXX, *FLAGS, and Erlang-specific *FLAGS,
there's also explicit support for cross-compilation:

Cross-arch environment variables:
  REBAR_TARGET_ARCH to set the tool chain name to use
  REBAR_TARGET_ARCH_WORDSIZE optional (if CC fails to determine word size)
  fallback word size is 32
  REBAR_TARGET_ARCH_VSN optional (if a special version of CC/CXX is requested)



More information about the erlang-questions mailing list