Search code examples
clangclang++llvm-clang

clang - build with default flags


I want to use clang for cross compiling. I've found out that it seems very easy, I can specify architectures/includes etc. just as I invoke clang directly.

However, I don't want to keep passing those flags, I'd rather compile clang so that it would have these by default.

That is, when I invoke clang just as clang++ main.cpp I'd like it to become clang++ -i686-w64-mingw32 -target-isystem=/usr/some/path main.cpp etc, how can I do that?


Solution

  • You can use a response file to do this sort of thing, it's also how you'd avoid command lines that are too long for your OS.

    Something like:

    clang @target_cmds.inc -c foo.c
    

    will likely work for you.

    (In addition to the earlier comments of some build system hackery or an alias, you could also define clang as a wrapper script that you invoke that does the same thing, e.g.:

    #!/bin/sh
    clang -target i686-w64-mingw32 -target-isystem=/usr/some/path $@