Xcode objective C++ -- avoid making .hh files? - xcode

To get header files with both Objective C and C++ objects to work, I have to rename them from .h to .hh. But my colleague uses .h with no problems. Neither of us understands why.
Can anyone explain?

I guess your colleague's project settings have the Compile Sources As set to Objective-C++ and you don't.

Related

Building a C static library using recent Xcode? Including that in Swift?

Does anyone have a guide to setting up a project that produces a static library under recent versions of Xcode? There are a few for older versions, but they use a project setting called "C/C++ Library" which seems to have been removed.
I notice "External build system" is still in there, and maybe that's a solution? The C code won't be changing structure too much, so a makefile could be a solution - but I've never used this type before, so I'd like to hear from people that have.
Ultimately the C code will be consumed by a Swift/Cocoa application. Am I correct in thinking that I simply include both projects in a workspace, drag the .a and bridging .h into the Swift project, and go?

How to add a .mm file into the project?

I need to add a .mm file which contains both ObjectC and C++, I am wondering how to do it using XCode 4?
There are absolutely no issues in doing that, just add the .mm fle to the project and XCode will compile it as Objective-C++.
The only caveat is that the .h associated with that ObjC++ code must not contain any C++ specific code or every file in which that header is included must be .mm too.
This because XCode will use different compiler according to the single file, so if a .m is found it will try to compile it as plain ObjC and not ObjC++. You can force to compile it with che ObjC++ compiler but I suggest you to follow the principle described or rename other files to .mm just to avoid getting things complicated.

Xcode flex lexer not generated

I'm having an issue with xcode. My project has a lexer which should be created (from lexer.l) before compiling anything. Flex should create two files from lexer.l: lexer.c and lexer.h. The latter is included in some other files. What happens now is Xcode does not process lexer.l and then complains about missing lexer.h. lexer.l is include in the compile sources list under build phases. Any thoughts?
One year late I can provide a solution. Maybe someone else can use it.
As I read on some answer on SO Xcode needs some special file extensions to map them to the different programming languages. When you want to compile c++ code f.e. you have to give the lexfile the ending .lpp. Xcode will handle the rest

Xcode .m vs. .mm

In the zxing iphone project the readme states:
It can happen that when trying to build your own project with
ZXingWidgetController you get linker
errors like "undefined reference to".
If this error looks like a c++
undefined reference, then renaming
main.m into main.mm (Objective-C++
source suffix) may fix the problem
It did indeed. But I'm wondering why?
.mm extension stands for Objective-C++, when compiler can process C++ classes.
But when using .m extension it will be able to compile only C code, without C++ classes.
Both .m and .mm are class file extensions of source code for Mac-based applications. .m files can contain both Objective-C and Objective-C++ classes. To avoid conflicts between the two in mixed-use scenarios there's the convention to rename all Objective-C++ class files to .mm. This helps compilers to distinguish.
So in a project which uses both Objective-C and Objective-C++ you will see:
.m files containing Objective-C
.mm files containing Objective-C++

Porting code from Linux to Windows

I'm using Visual Studio .NET 2003, and I'm trying to port code I've written and compiled/run successfully in Linux GCC to Windows.
I'm a newbie when using VS. I've created a new project, and added all the .c and .h files I have into the project by Project -> Add Existing Items, then chose all the .c and .h files.
I'm not familiar with how exactly compilers and linkers etc work, but is there a difference between how VS and gcc compile/link #include files? My habit of programming in Linux has been to have one main.c file, and #include all other .h or .c files that I need. Then I would only compile the main.c file. But in VS, it seems as if the #include files are not "seen" by the program, because I'm getting errors that tell me certain structures or variables were not declared, even though they are in my user-defined header files.
I'm also getting errors like DIR is an undeclared identifier. I've included , so why can't it recognize DIR?
Thank you.
Regards,
Rayne
Consider compiling your program with windows port of gcc (from Mingw32 or Cygwin) first. This will provide you with more familiar environment. If you'll still have to compile everything with VC++, you'll have more incremental process of porting.
Also, it is not evident from your post, but it seems you are trying to use dirent.h. Note that dirent.h (and corresponding libs) is not included with VC++.
One of the best ways to learn would be to start with the smallest application that you can compile on both. Expand this working and portable application step by step into the more fully featured application you desire.
Remember to add all .c/.cpp files to the 'Source Files' directory in the project as they won't be compiled otherwise.
Restrict any non-portable code (that you will need) to a single place. For example if you need to create threads, have a common create thread function used throughout (but implemented differently). Using portable libraries such as Boost can help here.

Resources