gcc precompiled headers weird behaviour with -c option

后端 未结 1 489
暖寄归人
暖寄归人 2021-02-04 21:02

Short story:

I can\'t make precompiled headers work properly with gcc -c option.

Long story:

Folks, I\'m using gcc-4.4.1 on Linux and before trying preco

相关标签:
1条回答
  • 2021-02-04 21:39

    Ok, I think I've found the solution: -fpch-preprocess should be used alongside with -c option. It works like a charm!

    Here's the timings:

    with pch

    $ time g++ -I. -include pre.h -c foo.cpp -fpch-preprocess
    
    real    0m0.028s
    user    0m0.016s
    sys 0m0.016s
    

    without pch

    $ time g++ -I. -c foo.cpp 
    
    real    0m0.330s
    user    0m0.292s
    sys 0m0.044s
    

    Update: I asked the same question on the gcc help mailing list and Ian Lance Taylor explained this strange behavior by my usage of distcc/ccache. These tools first preprocess the source that's why this options is required.

    0 讨论(0)
提交回复
热议问题