[m-users.] Pass options to gcc compiler

Julien Fischer jfischer at opturion.com
Thu Nov 17 09:54:15 AEDT 2022


On Wed, 16 Nov 2022, Sean Charles (emacstheviking) wrote:

> Final working solution in case it helps anybody but I doubt it as I am usually the stupidest person in the room:
> SDL2FLAGS=`pkg-config --cflags sdl2`
> SDL2LIBS=`pkg-config --libs sdl2`
> FLAGS=-s $(GRADE) -O4 -E --cflags "$(SDL2FLAGS)" $(SDL2LIBS) -lsdl2
> 
> Works fine, not sure why I had to do it this way now but as I say, there ain't no cure for stupid.

You had to do it that way because in general Mercury compiler flags and
C compiler flags are *not* the same thing.

Your FLAGS variable contains:

     -D_THREAD_SAFE -I/opt/homebrew/include -I/opt/homebrew/include/SDL2 -L/opt/homebrew/lib -lSDL2

For the Mercury compiler, -D does not define a C macro -- it's actually
an undocumented developer option.  Likewise, for mmc -I is a synonym
for --search-directories and that option affects where the Mercury
compiler searches for files, not the C compiler.  The mmc equivalent to
gcc's -I is --c-include-directory.

(-L and -l are equivalent for both mmc and gcc, but they're the
exception rather than the rule.)

Using --cflags to pass flags directly to the C compiler, as you have
done above, is one option.  (If you are grabbing pkg-config output, it's
probably the most convenient.)  Alternatively, you could use equivalent
mmc flags, e.g. --c-include-directory etc.

Finally, you could set the CFLAGS variable in a Mercury.options
file.  (Or indeed GCC_FLAGS if you have flags that you only want to pass
to GCC but not some other C compiler.)

Julien.


More information about the users mailing list