A Stack Overflow post about data structures said you can use STL in Objective-C and iOS development. The link he gave has the link to STL download as http://www.sgi.com/tech/stl/
It is nothing but header files and I'm not sure whether I need any other files. But let's say that works. I thought I could just put the files in a folder in my project folder and add them all to the project I have, so far a simple chat client. But would that cause them all to load in my file view? Is there a right way to do this?
all you need to do is to rename the file to *.mm. this tell the compiler it is Objective-C++ code. you can use both Objective-C object and C++ object at same time.
then if you want to use vector, just #include <vector> and use it like in normal C++ code.
Related
I'm a C++/Python developer recently starting to learn Swift and trying out iOS programming. I have a machine learning model that I've converted into Apple's Core ML format, and have successfully been able to use it in an iOS app in Swift, such as initializing a model with:
var model = MODELNAME()
Now, I have some existing C++ codes that I want to integrate into the app. A simple way to do this is to create a bridging .mm file in Obj-C, and wrapping the C++ code in Obj-c. By itself, the Obj-C wrapper and the C++ codes work without a problem with Swift, and I've been able to use the C++ functions in the iOS Swift app.
However, I noticed a rather confusing bug when I tried to load the Core ML model in the mixed Swift/Objective-C project. If I add .m source codes - even empty files - into the project (which automatically creates a bridging file Project-Bridging-Header.h), the compiler would report an error of "Use of unresolved identifier MODELNAME" for the Core ML model in the Swift code. On a Mac, simpling adding one .m file will cause the project to fail to compile. On iOS, adding one .m file is okay, but adding two .m files causes the same error to appear. Note that, only the .m (and by extension .mm, .cpp) source files affect the compiler, and header files do not.
I'm rather confused with this error...(since somehow, the sheer number of Obj-C sources in the XCode "compiled sources" list - not their contents, affects whether the Core ML model can be compiled). My guess is this might have something to do with how XCode automatically generates a header MODELNAME.h for Core ML models (which usually do not need to be explicitly imported in the code) and this somehow interferes with Obj-C bridging headers Project-Briding-Header.h and the Obj-C source codes.
May I ask if anyone has met similar problems or might have an idea of the reason behind this phenomenon? Thanks!
Screenshot of the project files
My project uses objective c++. I have to enable modules but when I Set "Enable modules" to YES my project starts to prompt lots of errors that I don't know how to handle them. I have set "Build Active Architectures" to NO and added -fmodules and -fcxx-modules.
I have to mention that my project is pretty old (7 years).
Attached part of the error's log.
It looks like it messes up everything.
error log
There is a problem with your include paths somewhere. The system-supplied header tgmath.h has a line that says #include <complex.h>. That should be resolved as a "system" file. Instead, your log shows it referencing something in another path (.../dmz_files/Eigen/.../Complex.h).
Contributing to the problem is the Mac file system, which doesn't do a good job of distinguishing between "complex" and "Complex".
The actual errors are coming from trying to interpret C++ code in an Objective-C context, but those are rather irrelevant compared to referencing the wrong file.
(Why this should be specific to modules, I do not know.)
I made a framework, The files I chose to make public were .h and .m files. I found that if I modify the contents of the .m file directly, it won't take effect. So what should I do to take effect?
Maybe I'm misunderstanding your question, but in the abscence of other answers let's see if I can help:
I made a framework
So you wrote some text into some files; then you used a tool, probably Xcode, to invoke the compiler, which interpreted that text as Objective-C and produced machine code in another file, and then constructed a framework bundle for you.
The files I chose to make public were .h and .m files. I found that if I modify the contents of the .m file directly, it won't take effect.
So now you edit your text file, and what do you expect to happen - not sure. Do you expect the framework code to change? If so aren't you missing a step compared to the above?
So what should I do to take effect?
Well that depends on what your goal is here. If you want your users to be able to customise your framework in some way then you need to design a method to do that using whatever tools you can when iOS is your target (Apple has rules).
This answer isn't much, but hope it helps.
I got an API for a lib file.
With that lib file .h files were supplied.
Now i want to call the lib file within the Delphi, and use its functionality.
how does the lib file get connected to the Delphi?
update: ok allot of work around is needed, what if i get a dll? how do i link that into the Delphi?
You can't use a lib file to link to a DLL from Delphi. The .lib file would be used by C or C++ clients of the DLL.
In Delphi you need to manually translate the .h header file into a Pascal import unit using the external keyword. An example of this of the Windows.pas unit in the Delphi source. The fact that you can't use the .lib file is actually not a big issue because you have to translate the .h file no matter what.
In certain cases it is possible to extract members of a .lib file using tools like the object file converter from Agner Fog (see http://www.agner.org/optimize/?e=0,34,36) to .obj files.
The syntax is
objconv.exe libname.lib -lx
to extract all members.
By extracting all members you can ensure that there are no members missing. However, if there are further dependencies (to other .lib files) these won't be resolved and must be resolved manually.
Also translating the header files is still required.
Note: The object file format can also be converted. Delphi only understands OMF, while Intel compilers (for exampl) spit out only COFF. Thus a conversion is required, which can be done by the tool as well.
As said this only works in certain cases and it surely need some expertise in this area, because the compiler won't help much with error messages (often the messages are irritating and misleading).
I'm currently porting a rather big project from C++ Builder 5 to the newest version, C++ Builder XE. It's my first experience with C++ Builder. I'm stuck with an error in a file, but I don't want to include this file anyway (it's code of a component not required anymore). I was not able to find out where and how this file is included, however. The compiler error does not give any hint at all apart from the error itself. How do you usually find out where a file is included?
The preprocessor is perfect for this. Right click on the cpp file which gives you the error in the project manager then choose "preprocess"
The output from this tells you every file and line number in the order they are processed. You can then search for the file in question, and the line above it is the file that included it.
This could conceivably be another header file as well, so it could be a long chain, but you can determine exactly where it comes from.
In the Project Options, enable the compiler's general messages. When the compiler encounters an error, you will be able to see the chain of includes that lead to the erroneous code.
If the files in question are rather sizable, a tool like Doxygen can be helpful in showing you the include dependencies (as well as call paths, etc.).
If it's just once or twice you'll have to do this, David Dean's suggestion of the preprocessor is golden.