Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Using agk:: functions in other cpp files than just template.cpp

Author
Message
Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 13th Jun 2017 01:37 Edited at: 13th Jun 2017 16:54
Hi,
I have been trying for a good while to write my own classes (with their h/hpp and cpp files) and call agk:: functions from them, in Xcode.
But every time I do so I get compilation errors. Writing a #include "agk.h" or using namespace AGK; won't help. See my next post.
I am including a very simple example, that I would like to have it work. Again, writing a #include "agk.h" or using namespace AGK; won't help.
How can I make this work?
Do I have to give up using cpp files--other than template.cpp--that employ agk:: functions?

Thank you

The attached files have this small code:


and

iMac Book Pro, MacOS 10.12.4, Xcode 8.3.3;
iPhone 6, iOS 9.35; iPhone 5s, iOS 9.35; iPad (3rd gen), iOS 9.35;

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2015;

Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 13th Jun 2017 08:01
If you want to use agk functions, you need to include the agk headers like so.



Hope that helps.
Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 13th Jun 2017 16:28 Edited at: 13th Jun 2017 16:43
I'm afraid that doesn't work (it may be a problem with Xcode). For example, suppose my two new files are

Testclass.cpp

and

Testclass.hpp


Then Xcode will throw the following buildtime messages:



It all boils down to some Unknown type name 'NSString' error message.
I have tried all inclusions of "agk.h" in both the header file Testclass.hpp and the implementation file Testclass.cpp . I have also tried the using namespace AGK in the header and cpp files, and all possible permutations thereof; and still, Xcode will throw buildtime errors usually related to this Unknown type name 'NSString' message.

Any other suggestions to fix this?
Or must I give up using cpp --other than template.cpp-- files in Xcode?
iMac Book Pro, MacOS 10.12.4, Xcode 8.3.3;
iPhone 6, iOS 9.35; iPhone 5s, iOS 9.35; iPad (3rd gen), iOS 9.35;

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2015;
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 13th Jun 2017 16:59
Try this link

https://stackoverflow.com/questions/26003727/xcode-6-unknown-type-name-nsstring-expected-identifier-or
The coffee is lovely dark and deep,and I have code to write before I sleep.
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 13th Jun 2017 17:48
This post has been marked by the post author as the answer.
As Stab in the Dark's link explains, the problem is that your code is being build as C++, but the AppGameKit headers include Objective C, which causes your build error, so you need to compile your new classes as Objective C as well. The answer in Stab in the Dark's link suggests rename the file. Personally, as I share source files between all platforms, I prefer to simply select the files in Xcode and set them to build as Objective C rather than C++, but either solution should work. Let us know if you need any more help with this.
Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 14th Jun 2017 18:41 Edited at: 14th Jun 2017 18:45
Awesooooommmmmeeeeeee!!!!!
Thank you so much. I included the "agk.h" header at the top of the cpp file, just like @Stab said and I'd tried before and I posted above. But then I went to Buid Settings>Compile Sources As> and set Objective C++ instead of according to file like @Lucas suggested. And that did the whole trick!
Thanks a lot to both of you!!!
Cheers
iMac Book Pro, MacOS 10.12.4, Xcode 8.3.3;
iPhone 6, iOS 9.35; iPhone 5s, iOS 9.35; iPad (3rd gen), iOS 9.35;

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2015;

Login to post a reply

Server time is: 2024-11-24 14:40:08
Your offset time is: 2024-11-24 14:40:08