How to compile specific files in objective-c++ and the rest of the project in objective-c - objective-c

I'm currently busy on a project where I need to use an external accessory to read Mifare 1k tags.
The accessory was provided with an SDK, written in (Objective ?)C++ and I followed the instructions provided to set XCode to "Compile sources as: Objective-C++" and added "-Obj-C++" in "Other linkers flags.
The SDK compiles fine then, but trouble is I am already using several libraries in the project (such as ASIHTTPRequest, JSONKit, ...) and I get compilation problems because of those new settings in those libraries. If I switch back to the previous settings, I get compilation problems in the reader's SDK
The question is: is there a way to compile only the class from the SDK as C++ and the rest of the project as objective-c ?
Edit: the SDK files consists only of .h (and a linked library)
thanks for your help,
Mike

Select the file you want to compile as Objective C++ from the file navigator, and then select the File Type in the file inspector view. This is in Xcode 4, but there is a similar mechanism in Xcode 3.

Try renaming the files where you are including the library headers to myClass.h for interface and myClass.mm for implementation files. This forces the files to be compiled as objective-c++.

I have resolved this problem:
You should set "According to file type" to "Complile Sources As",
Set "-ObjC++" to the "Other Linker Flags"
The last,you should modify the files's suffix to .mm that reference
the library method

well, in Build phases tab, there is a section Compile sources. For file you want to use Objective-C++ compiler add flag: -xobjective-c++
tested in Xcode 12.5

Related

How to identify unused methods in a framework included in a Swift project?

I am analyzing a swift application that includes several frameworks containing object .o files compiled from Objective-C source files, and the respective headers.
Very few of the methods in the framework libraries are being called so I want to identify what is unused. Is there a tool or linker setting that will do this?
I've found this but it doesn't work for frameworks:
https://github.com/PaulTaykalo/swift-scripts
Thanks.

scons and ObjC++

I'm trying to use scons to build a cross-platform cpp project. Some of the files contain ObjC code, which is only included on OSX and hidden behind ifdef guards on other platforms.
On OSX, I need to include a few -framework compiler/linker options, which I do through
env.AppendUnique(FRAMEWORKS = Split('Cocoa CoreAudio AudioToolbox AudioUnit GLUT OpenGL'))
in my SConstruct file as it says in the docs.
However, the FRAMEWORKS variable only gets used for .m and .mm files, whereas mine all have the .cpp extension. I want to keep it this way, since they're only ObjC files on OSX, and just cpp on other platforms.
Is there a way to get scons to treat source files with a .cpp extension as ObjC++, to get it to use the FRAMEWORKS env var?
I checked the sources of the current version 2.3.4 and there is no support for the FRAMEWORKS variable when compiling source files, only for linking (applelink.py Tool).
So you'd have to define your own ObjC Builder, which then could use the already defined variables like $_FRAMEWORKPATH, $_FRAMEWORKS and $FRAMEWORKSFLAGS.
If you need more help with that, you might want to come over to our user mailing list scons-users#scons.org ( http://www.scons.org/lists.php ) where we could talk you through all the gory details. ;)

iOS xCode how to purge Objective C++ from a project?

I got a demo project that had a single Objective C++ source file. I removed the file and renamed all files that touched it from .mm to .m . However, xCode still thinks that there is Objective C++ code in my project and refuses to refactor class names, etc:
I tried deleting the file I want to refactor from xCode project using Delete > Remove references, then re-added it. The file has .h and .m, nowhere does it import any .mm files. xCode still would not refactor, complaining about objective C++.
How can I disable/ purge Objective C++ from an xCode 5.1 project if I already removed and renamed all files? Is there some build setting I need to flip?
Apple Update Objective-C version 2.0 then they enable feature to allow C++ language variant with GNU & clang Compiler with certain restriction
Anyway
Apple & development team know why remove Objective-C++
But in Current Objective-C++ project not open And you Stuck So simply Go to your Project Folder And Rename Objective-C++ project file extension from .mm to .m , still work as well
What Objective-C++ Remove

Xcode 5 compilation

I've got a project which is going to be a c++ library for use in other c++ code.
It's made of a single .cpp implementation file and a single .h file for the interface. Normally I'd just compile the .cpp implementation file and then link it with other files with g++ in something like Ubuntu, however in Xcode 5 there's the Option Product>Build, Product>Build for... Running,testing, profiling and then there are the Perform action options to compile analyse, pre-process and assemble individual files. So with Xcode 5 how exactly do I complete my c++ library project in that I can then include it in other programs? And what happens when I use the options mentioned above like build and compile, because I see no new output files even though the build is successful - I'm guessing they go somewhere else I don't know about. I've googled this but I mostly find Xcode 4 stuff.
Thanks,
Ben.

Xcode linker flag -force_load for static library which is built in project [duplicate]

Some libraries require the -all_load linker flag when linking to an Xcode project. However, this leads to a linker error if there are symbol conflicts among libraries. The solution is to use -force_load, which effectively lets you use -all_load on some libraries, but not on others.
However, this in turn leads to a new problem, at least for me. Whenever I use -force_load with a relative path to a library, the linker always finds symbol conflicts between the library and itself. It appears that the linker thinks that the library with its absolute path and the library with its relative path are different libraries, and therefore finds conflicts between the library and itself.
I can avoid this by using an absolute path with the flag. But this is not a wonderful solution, as it is convenient to keep source code for libraries within my documents directory. But the path to the documents directory will be different on other machines.
Question: Can anyone get force_load to work with a relative path to the library?
EDIT: for background information, see this question
With Xcode 4, if you include the library project into your app project, then you can add this to the Other Linker Flags:
-force_load $(BUILT_PRODUCTS_DIR)/<library_name.a>
You still need the dependency, and you need to add the library in the Link Phase list of frameworks and libraries too.
EDIT: Apple now says as of some Xcode 4 release that you can simply use this linker flag: "-ObjC" to get libraries with categories to properly load. That flag is working just fine for me in Xcode 5. People are still up voting this answer, but I suspect that the -ObjC flag is the best solution now.
This worked for me. Like the above answers you still need to include the library in the project.
-force_load $(SRCROOT)/pathToLibraryFromProject/libname.a
For the path it's just the folders in your project that lead to where you put your library, for example BaseFoler/Subfolder/libName.a.