• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Using C++ classes with Objective C code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using C++ classes with Objective C code


  • Subject: Using C++ classes with Objective C code
  • From: John Nairn <email@hidden>
  • Date: Fri, 10 Oct 2003 10:24:27 -0600

I want to use some C++ classes in a project that it otherwise all
Objective C. My attempt was to

1. Add the C++ classes to the project
2. Create an ObjC++ file (with extension .mm) to serve as interface
between main code and C++ classes. Whenever the main code needs results
from C++ classes, it will call functions in this interface file that
isolate pure Objective C code from C++ code.

At first it would not compile, but after cleaning the target, it
compiled, but now it will not link. When I try to call a function in
the interface (.mm) file, there is a linking error ("Undefined
symbols:") which corresponds to the called function in the interface
(.mm) file.

I have used these C++ classes in another project, but it that case most
Objective C files needed to use them so I just made every file have
extension .mm. How come the above process does not link?

It case it helps, here is some code

>>>> File DateFunctions.h (header for interface file)

NSString *GetDateYear(NSString *);

>>>> File DateFunctions.mm (the interface file)

#import "DateFunctions.m"
#include "FullDate.h"

NSString *GetDateYear(NSString *dateStr)
{
FullDate fd;
fd.SetFromString([dateStr lossyCString]);
return [NSString stringWithCString:fd.YearString()];
}

>>>> Relevant code from File "Expression.m" (the Objective C file)

#import "DateFunctions.h"
.
.
.
dateStr=@"AUG 0045 BC";
NSString *year=GetDateYear(dateStr)

>>>> Finally, my project Prefix header file has

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif

------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page: http://www.eng.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Using C++ classes with Objective C code
      • From: "Alastair J.Houghton" <email@hidden>
  • Prev by Date: Re: how to warn users of wrong system
  • Next by Date: Re: how to warn users of wrong system
  • Previous by thread: Re: how to warn users of wrong system
  • Next by thread: Re: Using C++ classes with Objective C code
  • Index(es):
    • Date
    • Thread