0

I'm using the AppGameKit 2 C++ libraries with Xcode.

I'm using a template project that's given for development on Mac OSX and my code is identical to the default template save for changing a initWithCString to initWithUTF8String, but it compiled after that anyway, so it's not a problem.

The problem started when I tried to rename one of the classes that comes with the template, called template.h/.cpp. The option to rename in the refactor menu was greyed out, so I duplicated the class and changed all of the #includes to point to the new class, then removed the old one from the project.

When I hit run, I got about 20 errors all saying stuff like Unknown type name 'NSString' and Unknown type name 'Protocol'.

I looked around and found answers like this one: ios - Parse Issues in NSObjCRuntime, NSZone, and NSObject but it didn't solve the issue, because according to those, my code should work.

The includes of the main class (Core.mm) is here:

// includes
#import <Cocoa/Cocoa.h>
#include "agk.h"
#include "template.h"

The code in template.h is here:

#ifndef _H_APP
#define _H_APP

// Include AGK libraries
#include "agk.h"

// used in Core.mm to set the window properties
#define DEVICE_WIDTH 1280
#define DEVICE_HEIGHT 720
#define WINDOW_TITLE "Title"
#define FULLSCREEN 0

// Global values for the app
class app
{
    public:
        // global game vars
    public:
        // constructor
        app() {}
        ~app() {}

        void Begin( void );
        void Loop( void );
    void End( void );
};    
extern app App;
#endif

The code in template.cpp is here:

// Includes
#include "template.h"

// Namespace
using namespace AGK;

app App;

void app::Begin (void){
    agk::SetVirtualResolution (1280, 720);
    agk::SetClearColor(0,0,0); // light blue
    agk::SetSyncRate(60,0);
    agk::SetScissor(0,0,0,0);
}

void app::Loop (void){
    agk::Print( agk::ScreenFPS() );
    agk::Sync();
}

void app::End (void){}

I can't make any sense of this because it shouldn't make sense.

Community
  • 1
  • 1
JamEngulfer
  • 747
  • 4
  • 11
  • 33

3 Answers3

2

Well, I found the problem. In the template project, the template.cpp file was marked as an Objective-C++ source file, but it obviously wasn't being reimported as one. Changing the file type fixed the problem.

JamEngulfer
  • 747
  • 4
  • 11
  • 33
2

Xcode 11.7

( in 2020 )

change the type, to do it more intuitively

111

black_pearl
  • 2,549
  • 1
  • 23
  • 36
0

This is cause you imports C or C++ file in your project.For this you add all your header file that imported in .pch file or any common file should declare like this:

#ifdef __OBJ C__
//Import header file
#endif