[Interest] [OS X] How to enable ARC for *.mm files (which qmake var)?

Till Oliver Knoll till.oliver.knoll at gmail.com
Fri Jan 17 21:20:29 CET 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 17.01.14 00:55, schrieb Thiago Macieira:
> On sexta-feira, 17 de janeiro de 2014 00:07:07, Till Oliver Knoll
> wrote:
>> QMAKE_CXXFLAGS += -fobjc-arc QMAKE_CFLAGS_DEBUG += -fobjc-arc 
>> QMAKE_CFLAGS_RELEASE += -fobjc-arc
>> 
> 
>> That is, the expected -fobjc-arc flag is only applied for
>> clang++.
> 
> "CXXFLAGS" applies to C++ and Objective C++.

Are you /sure/ you mean CXXFLAGS and not QMAKE_CXXFLAGS? In fact, I
just tried setting CXXFLAGS and it does not seem to have any effect:

  CXXFLAGS += -fobjc-arc

- -> the compiler flag is /not/ added, neither when compiling my ObjC++
*.mm files (as expected), nor to my C++ *.cpp files.

  QMAKE_CXXFLAGS += -fobjc-arc

on the other hand /does/ add that option when compiling my C++ files,
but naturally enabling Automatic Reference Counting (ARC - a feature
which makes only sense when compiling Objective C/C++) has no effect
in the C++ world.

> If you want it for C and Objective C, you need QMAKE_CFLAGS.

According to

  http://qt-project.org/doc/qt-5/qmake-variable-reference.html

the variable QMAKE_CFLAGS does not exist (at least it is not
documented). So I assume that it would work for C files in analogy to
how QMAKE_CXXFLAGS works for compiling C++ files (which /is/ documented).

However I really need to have the flag for Objective-C++ files, not
just Objective-C files, and I did not try whether the flag would
actually be used for Objective-C files at all, given the solution that
I found, based on your following comment...


> Note that this will get the flags for plain C and C++ sources too.
> 
No, setting

  QMAKE_CFLAGS += -fobjc-arc

has no effect, neither on the *.mm nor on the *.cpp files. At least
that flag was not set when clang++ was invoced. And to be honest, I
would not expect flags set for a C compiler to take effect when
compiling C++ sources either.

However the following did the trick:

> You may want to use QMAKE_OBJECTIVE_CFLAGS.

That did the trick! Again, that variable is not documented anywhere in
the official Qt docs, but the flags was set when "clang" was invoced
and I could see that it took immediate effect, since clang freaked out
about missing "bridged casts" (from the Core Foundation/C world into
the ObjC world), since the ObjC code in question is some Apple example
code which was written in the pre-ARC era ;)

> I don't see an equivalent flag for ObjC++.

I don't see e.g. QMAKE_OBJECTIVE_CXXFLAGS either (and it does not work).

But when you mention "see" you probably refer to various Qt project
*.pro files, GIT commit messages of "Chromium" etc., as in

  https://www.google.ch/search?q=QMAKE_OBJECTIVE_CFLAGS

There is even a link


http://code.mythtv.org/cgit/mythtv/commit/?id=57baf5ba8e07657fe8286dc075182541eea32f02

where some commit message mentions:

"Depending on the version of Qt you are using QMAKE_OBJECTIVE_CXXFLAGS
may be ignored and QMAKE_OBJECTIVE_CFLAGS is used instead. So define
both."

That is pretty much the only documentation about it I "see" so far ;)


Thanks a lot!
  Oliver

P.S. If anyone reading this feels like updating the QMAKE
documentation accordingly - please go ahead :)





-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlLZkI0ACgkQHVnxr7UPh0PErgCgry8Q4qK7k8nnfO3WFpD4NSdQ
+YsAnRFEO/xqGrd1YpMYXT1cHDcqtpOi
=t9Wt
-----END PGP SIGNATURE-----



More information about the Interest mailing list