[Qt-interest] C Code with QMake

Konrad Rosenbaum konrad at silmor.de
Mon Aug 9 14:57:00 CEST 2010


On Mon, August 9, 2010 09:35, Oliver.Knoll at comit.ch wrote:
> Jeffery MacEachern wrote on Sunday, August 08, 2010 3:39 AM:
>> ...
>> Is it simply relying on the .c extension to determine that it should
>> use gcc for compiling the source, then?

> It then decides which actual compiler (C vs C++) to invoke AFAICR. Not
> sure whether qmake itself also takes the extension into account as to call
> either gcc or g++.

Correct for files ending in .c it uses $(CC) $(CFLAGS) as compiler and for
files ending in .cpp it uses $(CXX) $(CXXFLAGS) - whatever that is for the
platform you are using.

All those variables are seen at the start of the generated makefile.

For linking it always uses the same command $(LINK) $(LFLAGS) - whatever
that is on your platform. Because at that stage qmake does not remember
whether there were any C++ files it always uses the C++ compatible linker,
just to be on the safe side. That linker usually does not know and care
whether the object files it links were created by C or C++, when called as
backend by a C++ frontend, it includes all the C++ stuff to be safe as
well.

Your platform definition is part of the mkspec that you chose explicitly
or implicitly when building Qt itself.

So if your source is ANSI-C only you might as well direct qmake to use a
different linker - one that does not include libstdc++, ie. "gcc". I
recommend not to use "ld" directly, because this might omit libc as well,
which would be fatal.


    Konrad




More information about the Qt-interest-old mailing list