Compiling ObjC++ versus ObjC

Jeremy Huddleston Sequoia jeremyhu at macports.org
Wed Jan 23 16:10:43 PST 2013


On Jan 23, 2013, at 12:09 PM, Michael Dickens <michaelld at macports.org> wrote:

> On Jan 23, 2013, at 12:06 PM, Jeremy Huddleston Sequoia
> <jeremyhu at macports.org> wrote:
>> Yep, I think you hit the nail on the head.  In short, you pretty much want to do:
>> 
>> CC = clang
>> CXX = clang++
>> OBJCC = ${CC}
>> OBJCXX = ${CXX}
>> 
>> ${CC} ${CPPFLAGS} ${CFLAGS} -c my.c -o my.o
>> ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c my.cc -o my.o
>> ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c my.cpp -o my.o
>> ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c my.cxx -o my.o
>> ${OBJCC} ${CPPFLAGS} ${OBJCFLAGS} -c my.m -o my.o
>> ${OBJCXX} ${CPPFLAGS} ${OBJCXXFLAGS} -c my.mm -o my.o
> 
> OK; that's what I thought too, for the best possible implementation.
> 
> Strangely enough, QMake (even in Qt5, IIRC) does not do the above; they
> stop with ${OBJCC} and do not provide specific OBJCXX compiling (.m and
> .mm are combined into a single OBJC set of variables).  I can easily
> extend QMake to provide a separate compile chain for OBJCXX files --
> I've actually already done this (in a local build, not checked in) to
> get Qt4 building using -std=c++11.
> 
> My overarching goal in providing a separate compile chain is to allow
> current QMake builds to work correctly without requiring OBJCXX-specific
> variable setting since any other (non-MacPorts') QMake is not guaranteed
> to be able to (and, generally, will not) support this feature & hence
> programmers should be writing generic QMake build scripts and not
> tailoring specifically to MacPorts' version of QMake.  I want to make
> QMake outwardly compatible with all other QMake's, while internally
> mixing things up to work better for the projects using MacPorts' QMake.

Well, I encourage you to submit these change upstream, so developers *can* rely on them =)

> What I have done is created new OBJCXX variables that default to the CXX
> versions if not explicitly set otherwise.  Since QMake's OBJC variables
> default to their C counterparts, maybe I should instead set the OBJCXX
> ones to the OBJC variables for defaults instead to maintain outward
> compatibility?  Or, just set up a new compiler chain that uses OBJC
> variables but ${CXX} for the compiler so-as to entirely do away with the
> alternative OBJCXX variables?

No, you should fix it right (defaulting to $CXX).  For comparison, this is what autoconf does:

http://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Objective-C_002b_002b-Compiler.html

--Jeremy



More information about the macports-dev mailing list