Compiling ObjC++ versus ObjC

Jeremy Huddleston Sequoia jeremyhu at macports.org
Wed Jan 23 09:06:02 PST 2013


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

--Jeremy

On Jan 23, 2013, at 8:34 AM, Michael Dickens <michaelld at macports.org> wrote:

> I'm working on adding a c++11 variant to qt4-mac, which requires that
> all of the Qt libraries be compiled using "-std=c++11".  Most of Qt
> compiles without complaint, and the few files with issues are generally
> easy to correct once the build errors out.
> 
> Qt4 uses a bunch of what would by current practices be called ObjC++
> files (ending in .mm); I don't think any are just .m files (ObjC).  I
> find that /usr/bin/clang can be used to compile either .m or .mm files,
> but that it treats .mm files differently; sometimes I need to use
> /usr/bin/clang++ to get a particular .mm file to compile, and, really,
> in my testing all of the .mm files compile more reliably using clang++
> (and, without specifying anything more than the file extension; I could
> always drop in a flag to tell clang to treat the file as C++ or C or
> ObjC or ObjC++).  I do not have any .m file to test for compiling using
> clang++, so I have no idea if/how well that variant works.
> 
> So, in my limited experience, it seems to me wise to use clang (${CC})
> to compile ObjC (.m) files, and clang++ (${CXX}) to compile ObjC++ (.mm)
> files, with different flags (e.g., OBJCFLAGS, OBJCXXFLAGS) as well as
> common ones -- just like for CFLAGS and CXXFLAGS and their respective
> files (.c, .cc, .cxx, .cpp).  But, I have no practical (real world)
> development experience in any form of Objective C/C++.  So, I ask you
> MacPorts developers out there for your advice: should these files be
> treated differently, or can I just use clang++ and a single set of flags
> for both?  Or, some other combination / variants on the above?
> 
> Thanks in advance! - MLD
> _______________________________________________
> macports-dev mailing list
> macports-dev at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo/macports-dev



More information about the macports-dev mailing list