Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8352579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:59:59+00:00 2026-06-09T08:59:59+00:00

I’m trying to create a library in C++ in XCode, and I’m trying to

  • 0

I’m trying to create a library in C++ in XCode, and I’m trying to use it inside an iPhone project. I’m using XCode 4.3.2. Since there’s no ready template available in iOS development to create a C++ library, I’m using the Mac OSX – Framework & Library -> C/C++ Library option.

In this project, I’m having .h and .cpp files. I purposely want to keep my C++ code in .cpp files since it may later be used on Android or Windows 8. In order for it to link against a sample iPhone project, I’ve modified the project’s target to point to Latest SDK iOS 5.1, and use the architecture armv6 and armv7.

Following is my .h file

#ifndef Test_Test_h
#define Test_Test_h
class Test {   --> I get the error here saying unknown type 'class'; did you mean 'Class'?

public:
Test();
~Test();
int addTwoNums(int a, int b);
};


#endif

Following is my .cpp file in my C++ library

#include <iostream>
#include "Test.h"
Test::Test(){}
Test::~Test(){}
int Test::addTwoNums(int a, int b)
{
return (a + b);
}

Now in order to enable function calls from within my iPhone project, I’ve created a wrapper layer embedding C++ objects inside a .mm class courtesy this article:
http://www.philjordan.eu/article/mixing-objective-c-c++-and-objective-c++

Following is the implementation of my wrapper header file which is part of my separate iPhone project

#import <Foundation/Foundation.h>
@interface TestWrapper : NSObject
-(id)init;
-(int)returnSumFromCpluspus:(int) a b:(int) b;
@end

Following is the implementation of my wrapper .mm file part of my separate iPhone

#import "TestWrapper.h"
#import "Test.h"
@implementation testWrapper
{
Test *tst;
}

-(id) init
{
self = [super init];
    if (self) {
    tst = new tst();
    if(!tst)
        self = nil;
}
return self;
}

-(int)returnSumFromCpluspus:(int) a b:(int)b
{
int result = 0;
if(tst)
    result = tst->addTwoNums(a,b);
return result;
}

- (void)dealloc
{   
 if(tst)
 delete tst;
}
@end

Now in my iPhone project, I’ve linked it against this static library. I’m able to compile and debug just fine only when I select a “compile sources as: Objective-C++” in my iPhone project’s target, and not my C++ static library project. If I change the compile sources as: According to the File Type”, I get compilation errors:

unknown type name ‘class’;did you mean ‘Class’?
Expected ‘;” after top level decorator.

My question is it compulsory to change my iPhone project property target compilation type as Objective-C++, and not my static library C++ project or is there another way, which I might be missing and not aware of?

Any help in this regard will be greatly appreciated!

Thanks,
Asheesh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:00:00+00:00Added an answer on June 9, 2026 at 9:00 am

    It would help us understand your problem if you edit your question to include some of the actual source code that the compiler doesn’t like.

    That said, I think you are trying to #include (or #import) a .h file containing C++ class definitions in a .m file.

    A .m file is (by default) an Objective-C file, not an Objective-C++ file, so the compiler will reject C++ constructs in a .m file. If a .m file includes/imports a .h file, that .h file must also contain only Objective-C code – not C++ or Objective-C++ code.

    You say that you have written a wrapper layer using Objective-C++. So you probably have a file named something like Wrapper.h that declares the @interface of your wrapper class, and you have a Wrapper.mm containing the @implementation (in Objective-C++) of the wrapper class.

    You need to make sure that Wrapper.h contains no C++ code. It can only contain Objective-C, because you are going to include/import Wrapper.h in your .m files.

    If your Wrapper.h includes/imports a header file from your C++ library, you need to take that out. You can only include your C++ library header files directly in your .mm files, or in other .h files that you only include from .mm files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.