Many C++ compile errors in iPhone project - c++

i am working on a C++ file in Xcode 4.5 on my iPhone application.
for some reason the compiler do not accept C++ statements, it gaves me many errors.
why does this happen?
any help would be appreciated!
thanks

CAStreamBasicDescription.h and CAXException.h contain C++ code. They can only be included from C++ or Objective-C++ source files.
The errors indicate that the file that is including those two headers is not being compiled as C++ or Objective-C++. The references to Class within the errors suggest that it's being compiled as plain Objective-C instead. Ensure that the file has a .mm file extension if you do intend it to be compiled as Objective-C++, and check that the Type is not set to a non-default value in the Identity and Type section of the File inspector.

Related

Using Cocoa static library built in c++, some ObjC code tries to rebuilt it in OC

I am programming in Xcode in ObjC using a Cocoa static library built in c++ (built by me). For the library project, I made one public header(.hpp) that includes all the other header files(.hpp). Then in the ObjC project, I wrote a wrapper code(.hpp and .mm) to play as the interface, so it includes the public hpp header. To access the library, I then include the wrapper code in a normal m file. I believe all of these followed the tutorials, as it worked well for a few weeks.
However, after doing something stupid yesterday, the compiler for the ObjC project started to insist on building all the headers in ObjC. It first had problems with openCV packages in the c++ library, producing errors saying thoses are supposed to be built in c++ (as shown below). Even if I removed the openCV, the compiler cannot find any standard c++ libararies. I tried renaming the .hpp's to .h but it did not work.
Any suggestions on what I did wrong and how I can fix this?Much appreciated!
()
Your errors are coming from compiling ImageProcessor.m. .m is the extension Obj-C files, so the compiler will try to compile it, and everything it includes as Obj-C.
I'd suggest renaming it to ImageProcessor.mm.
After learning more about header files, I realized what I did wrong: I included every header in the interface, so they are re-built every time outside the library, even if they are referenced by none-c++ code. The solution is to separate the interface header with other headers in the library completely.

What library to include for std::vector in Tizen?

I want to use an std::vector for an app that I'm creating with Tizen and I can't find the right library to include to make my std::vector be recognized...
I have a syntax error...
Is there an equivalent to std::vector specific to Tizen? I searched the web but I didn't find anything...
I tried #include <vector> Tizen doesn't recognize it, that's what my problem is because in "normal" C++ it works fine. Only I'm using Tizen with Tizen IDE (Eclipse plug-in) and it doesn't recognize the library so I'm wondering which library I need to include instead (I got a fatal error: file not found when I use the include I mentioned).
I can't post images so here's a transcript of the error message:
type name requires a specifier or qualifier
syntax error
expected expression"
All of which regarding this line:
std::vector<int> vect;
OK, I found my answer. It seems Tizen is using C and not C++... I didn't see it because some libraries I sometimes use when I code in C++ were included like they should. Anyway I'm just gonna have to find the C equivalent of vector now and my problem will be solved.
https://developer.tizen.org/dev-guide/2.2.0/
The Tizen C++ application supports C++ based on the Standard C++ ANSI ISO 14882 2003, which includes the Standard Template Library (STL). This helps developers migrate the pre-existing standard library based applications to the Tizen platform with minimum effort.
More specifically, Tizen supports complete set of libstdc++v3 comprising of standard C++ functions specified in the Standard C++ ANSI ISO 14882 2003 and the entire Standard Template Library (http://www.sgi.com/tech/stl/).
These methods can be used by including the relevant header file in a standard manner, for example, "#include <stdio>".
Support for standard C++ library extended to complete set of libstdc++v3 modules, namespaces and classes.
For more information, refer to this Web site.
Remarks:
The locale based feature is not supported in Tizen.
So #include <vector> should work fine.
Since you say that you can't include any C++ headers, I suspect the problem is that the compiler is compiling your code as C instead of C++. Affirm that your file has the .cpp extension, and view the file's properties in the project to confirm that the IDE is treating the file as C++. (I don't know where that setting is, I don't have Eclipse). This link says to delete your project and create a C++ project instead of a C project, then re-import your files. This link says you can set the "File Type", but also implies it doesn't quite work.
You say: I searched the web but I didn't find anything...
Google "std::vector" The first hit is
http://en.cppreference.com/w/cpp/container/vector
which says:
Defined in header <vector>
So the answer is: Learn to use Google.
I think the wrong answer was accepted...the clue is in the tags used by the OP.
The compiler used by Tizen studio determines whether a source file or header file is C or C++ based on the file extension. So if your header file is .h and you include < vector > then the compiler will complain since there is no C equivalent library for vector.
If you rename you header to .hpp, or your source to .cpp, and recompile then it will compile without error.

Import C++ code to IOS application [duplicate]

This question already has answers here:
How can I use C++ with Objective-C in XCode
(2 answers)
Closed 8 years ago.
I write a code in C++, and I want to use some of it's methods in my IOS application, so is it possible to (import) C++ library "t.cpp" to IOS application in XCode?
if yes what's the simple way to do it?
Yes, that will work without error, however you might want to change the Xcode C++ compiler settings (language level and runtime library), depending on the version of iOS you are using.
When it comes to actually using the C++ classes within your Objective-C code, you simply need to rename any files from .m to .mm.
A complication occurs when you want to include the C++ headers in Objective-C headers where both .m and .mm see that Objective-C header file. In this case you might find that you need to change many more files from .m to .mm in order for this to work, but there are ways around this if that becomes too onerous.
Just add the file to the project.
You need to rename a file from .m too .mm only if the translation unit contains a C++ header. Then, the module gets "infected" by C++ and needs to be compiled with the Objective-C++ compiler.
This is only required if any C++ header will be directly or indirectly included/imported from that module. There is no need to rename all files.
Additionally, if this C++ code depends on the C++ standard lib, you need also ensure, that the executable binary links against the C++ standard lib, via setting the appropriate build setting in the executable binary.
For example, in the target build settings of your app, add the following option to Other Linker Flags:
-lc++
e.g.:
OTHER_LDFLAGS = -ObjC -lc++
Caution:
If possible, don't include/import a C++ header in a public Objective-C header, since then all modules will be infected by C++ when they import this Objective-C header and become Objective-C++.

Adding C++ code to an iOS project

I'm trying to add a C++ library to an iOS project. I added the source code files to the project, but seems like they are not interpreted like a C++ code.
For instance, I get the following error in a header file:
namespace soundtouch // Unknown type name 'namespace'
{
I already tried to change the type in the File inspector to "C++ Source" and "C++ Header" - nothing changed.
How can I import a C++ library to an XCode project?
C++ source files must have a recognised extension; .cpp, .cxx, .cc etc. and they will be compiled as C++ files. You shouldn't need to change the file type manually if the extension is correct (and recognised) when you add the file. The compilation language is determined on a per-module basis.
Intermixing C++ and Objective-C is a different story. There's a whole section in the ADC documentation on Objective-C++ (which uses the .mm extension). So if you want to call C++ code from Objective-C, it will need to be done from a .mm module.
Given the error you quoted, it looks like you're probably trying to include a C++ header file in an Objective-C module. To make this work, you need to rename the Objective-C module to .mm and then the compiler will treat it as Objective-C++.
It takes a little planning to determine a clean boundary between the C++ and Objective-C code, but it is worth some up-front thinking.
This article is worth reading:
Mixing Objective-C, C++ and Objective-C++
Every Objective-C implementation file (.m) that directly, or indirectly, #imports any of the C++ header files must be changed to an Objective-C++ implementation file by changing its file extension to .mm.

vcl.h: No such file or directory

I'm looking to compile some old source code in Visual C++. However, the first of many errors I am receiving is:
vcl.h: No such file or directory
This appears to be in reference to the Visual Component Library, native to Borland compilers it seems. I downloaded the free Borland C++ 5.5 command line compiler, but it doesn't seem to contain a vlc.h in its include directory.
How can I resolve my issue? Many thanks.
This old code must have come from C++Builder. If it actually uses the VCL, you won't be able to build it with any other compiler. If there are other VCL includes like classes.hpp, system.hpp, controls.hpp, etc. it is using the VCL.
If it is a console application and doesn't actually use any VCL classes, then you can probably just remove the include, but the chances are slim.
Borland C++ 5.5 and C++ Builder are two different products.
The VCL components are in the C++ Builder product and can't be compiled with Borland C++ 5.5 which is a pure C/C++ compiler (I think OWL is included there).
So you have to get your hands on C++ Builder to be able to compile it.