Precompiled header for c++ project with a .c file [linux]



  • Hello,
    I have a c++ project with precompiled header (stdafx.h) that compile fine. However, after adding a .c file to my project, it fails at compiling stdafx on

    #include <map>
    

    The new .c /.h files are completely independant from the other files, i.e. there is no include at all (beside <stdlib.h>) but it still try to build stdafx for a c project.

    The command from console log without the .c file :

    g++ -pipe -DQT_COMPILING_QSTRING_COMPAT_CPP -Wsuggest-override -Werror=suggest-override -isystem "/opt/Qt5.7.1/5.7/gcc_64/include/QtCore" -isystem "/opt/Qt5.7.1/5.7/gcc_64/include/QtWidgets" -isystem "/opt/Qt5.7.1/5.7/gcc_64/include/QtSerialport" -isystem "/opt/Qt5.7.1/5.7/gcc_64/include/QtTestlib" -isystem /opt/Qt5.7.1/5.7/gcc_64/include/qt5 -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DTEST_LIBRARY -DQT_USE_QSTRINGBUILDER -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SERIALPORT_LIB -DQT_TESTLIB_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR='"/home/dlevy/Perforce/dlevy_Builder04_LC3.3_main/Qt/main/Test"' -I. -I../TestTech -I../Common -I../Ltp_Production -I../LC4/main/src -I../LC4/main/src/Test -I../LC4/main/src/TestPrototypes -I../LC4/main/src/TestPrivate -I../LC4/main/src/TestTech -I../LC4/main/src/shared -I../LC4/main/src/shared/comm -I/opt/Qt5.7.1/5.7/gcc_64/include -I/opt/Qt5.7.1/5.7/gcc_64/include/QtWidgets -I/opt/Qt5.7.1/5.7/gcc_64/include/QtGui -I/opt/Qt5.7.1/5.7/gcc_64/include/QtSerialPort -I/opt/Qt5.7.1/5.7/gcc_64/include/QtTest -I/opt/Qt5.7.1/5.7/gcc_64/include/QtCore -IRelease -I/opt/Qt5.7.1/5.7/gcc_64/mkspecs/linux-g++ -x c++-header -c StdAfx.h -o Release/Test.gch/c++
    

    and with the .c file :

    gcc -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DTEST_LIBRARY -DQT_USE_QSTRINGBUILDER -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SERIALPORT_LIB -DQT_TESTLIB_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR='"/home/dlevy/Perforce/dlevy_Builder04_LC3.3_main/Qt/main/Test"' -I. -I../TestTech -I../Common -I../Ltp_Production -I../LC4/main/src -I../LC4/main/src/Test -I../LC4/main/src/TestPrototypes -I../LC4/main/src/TestPrivate -I../LC4/main/src/TestTech -I../LC4/main/src/shared -I../LC4/main/src/shared/comm -I/opt/Qt5.7.1/5.7/gcc_64/include -I/opt/Qt5.7.1/5.7/gcc_64/include/QtWidgets -I/opt/Qt5.7.1/5.7/gcc_64/include/QtGui -I/opt/Qt5.7.1/5.7/gcc_64/include/QtSerialPort -I/opt/Qt5.7.1/5.7/gcc_64/include/QtTest -I/opt/Qt5.7.1/5.7/gcc_64/include/QtCore -IRelease -I/opt/Qt5.7.1/5.7/gcc_64/mkspecs/linux-g++ -x c-header -c StdAfx.h -o Release/Test.gch/c
    

    I noticed at the end of the command that cxx-header became c-header.

    Is there something I am not doing correctly?

    Additionnal info:
    -No problem on windows
    -The header for the .c file is surounded by extern C



  • After reading the doc again, I found that I need to add

    #if defined __cplusplus
    /* Add C++ includes here */
    

    in my stdafx file. There is nothing related to the .c file, but I guess the compiler parse it once for the .c file, and another time for the .cpp files.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.