How to determine which command line options gcc passes to ld by default?

后端 未结 2 402
半阙折子戏
半阙折子戏 2020-12-31 13:24

Consider the hello world C program:

hello.c:

#include \"stdio.h\"

int main()
{
        printf(\"Hello, World!\\n\");
}
2条回答
  •  旧巷少年郎
    2020-12-31 14:00

    For oneline lovers:

    echo "int main(void) {}" | gcc -o /dev/null -v -x c - &> /dev/stdout| grep collect | tr -s " " "\012"
    

    Replace -x c with -x c++ to get c++ flags.

    Can be used also with clang, but in such case you should grep for /usr/bin/ld

提交回复
热议问题