Adding an Objective-C++ file to a C++ Xcode 5 project - xcode

I am attempting to add an ObjC++ file to a large Xcode 5 C++ project.
For legacy reasons, the "Compile Sources As" setting must remain "C++". If I could change this setting to "According to File Type" the ObjC++ file would build properly, but it won't compile if Xcode thinks its a C++ file.
I have tried explicitly setting the Type of the .mm file under Identity and Type to "Objective-C++ Source" and the compiler still attempts to build it as a C++ file. I have tried adding the "-ObjC" and "-ObjC++" compiler flags to to the individual file under Build Phases > Compile Sources, and I get a warning that the argument is unused during compilation.
I have tried this process in reverse, adding an ObjC++ file to a different project that is compiling sources as "According to File Type," and setting the Type to C++. As expected, the file fails to build. This shows that specifying the type of an individual file takes precedence over the project setting.
Is there no way to force Xcode5.1.1/llvm5.1 to build a single ObjC++ or ObjC file as the correct type? The project setting is overridden by the individual file setting in every case I've tested, except trying to build an ObjC++ file. Is this a bug or missing feature?

You were close with the ObjC++ flag.
Set the file's Compiler Flags in the Compile Sources Build Phase to -x objective-c++ $(inherited).

Related

Where are Linker Flags in External C Library?

I have a C library which I need to use in my ongoing Xcode project. I used Cmake to build and install that Library. I gave the paths to Headers files and I can include the files into my Xcode project. However, when I run the project it says:
linker command failed with exit code 1 (use -v to see invocation)
I suspect that problem is with Linker Flags. I haven't included any Linker Flags and I don't know which flags do I need to add. Please tell me where in the library would I get all the required Linker Flags.
git hub link of the library which I want to add:
https://github.com/cbalint13/pba
From xcode left side window.
Under Project Navigator, click on your project, click on build settings.
Select "All" and "Combined" sections, then search for "Linker Flag"
Don't forget to switch to your target's build settings as well. As you might change just the "Project", not the "Target".

Add "-fobjc-arc" flag on specific files from command line

I'm working on a non-arc workspace,for specific files I added "-fobjc-arc" flag BuildPhases>CompileSources>. When I try to automate the build I'm unable to add the compiler flags. I have multiple targets, so i should pick the required target and add compiler flags for files in the target. Can it be handled while generating the project with CMAKE?
Any help here would be appreciated.

CMake with Xcode 5 : how to add external libraries as 'Target Dependencies' instead of linker flags?

We are building our software under OS X (10.8 at the moment). The project build is managed by CMake (2.8.12).
External dependencies (i.e. not target added by project's CMakeLists) are handled using what we undestood as the canonical way :
Calling find_package(${external_lib}) from a root CMakeLists.
If a given target needs to link against the previously found package, the target's CMakeLists calls target_link_libraries(${TARGET_NAME} ${${external_lib}_LIBRARIES})
The procedure works nicely from a building perspective (the target is actually linked against the external library). Yet the external library is actually given as an additional flag to the compiler, in Build Settings::Other Linker Flags, when it seems that Xcode native way for doing this would be to add the dirname to Build Settings::Library Search Path, and the basename to Build phases::Target Dependencies.
Is there a way to achieve this behavior (without breaking the behavior for other platforms) ?
The behavior of CMake was changed years ago to use full paths.
http://www.cmake.org/cmake/help/v3.0/policy/CMP0003.html
Why do you want to split it?

Xcode 4 + llvm, How to ignore compiler warnings in specific directory?

I'm putting all my third party code in a /Vendor directory in my Xcode project. How can I suppress all compiler warnings in that directory?
I'm using Xcode 4 and LLVM 2.1.
You cannot set warning flags in Xcode by directory; directories have no meaning to Xcode, they don't form any form of "compile entity". You can set warning flags per Target, per Build Configuration, or on single files. This leaves you with two options:
Build all 3rd party code as an own target, e.g. make it a static library target, then build your code in another target and make it link against the static library of the first target. Each target can then have different warning flags.
Select all the 3rd party files in the list of files to build and override some of the warning flags (if a warning is turned on with -Wfoobar, then you can disable it with -Wno-foobar). Setting compile flags on single files is shown in the screenshot below; this can be done with multiple files at once.

Linking in Xcode

How do I make Xcode link object files properly?
The file containing "main" and all the dependencies compile properly (and I can easily link them in the command line to generate the executable). However, Xcode seems to refuse to do it, resulting in ld errors of "symbol not found".
This is what my current setup looks like. All the dependencies (Calculator, input, etc) are detected and compile properly. The cpp file contains main but fails to be linked to the .o file (generated by the dependencies), resulting in several ld "symbol not found" errors.
Any ideas?
.o's generated by dependencies do not get linked into the including target. In the example above, "Calculator" needs to generate something, generally a static library (.a), that you would then add to the list of libraries to be linked into the project.

Resources