Sign In Register

How can we help you today?

Start a new topic
Answered

iOS SDK -- XCode Linker Errors when using Real Time API.

I'm trying to use the iOS SDK -- specifically the Real Time functionality. The specific linker errors I get when trying to build my project look like the following:

  •   "_OBJC_CLASS_$_IRTSession", referenced from:
  •   "_OBJC_CLASS_$_GameSparksRTSessionBuilder", referenced from:
  • clang: error: linker command failed with exit code 1 (use -v to see invocation)


I get these linker errors whenever I:

(1) Use Real Time classes in the scope of a function

(2) Use Real Time classes as a variable of a class.


I do NOT get linker errors when I:

(1) Use the rest of the GameSparks API from the iOS SDK.

(2) Use RT classes as parameters in functions.


I installed the iOS SDK using cocoapods, in the normal way.


Example code (made using a fresh iOS SpriteKit game template, after removing some of the boilerplate code. GameSparks installed using cocoapods. Currently using XCode 8.3.3): 

   

import SpriteKit
import GameSparks


class GameScene: SKScene, IRTSessionListener {
    
    var session: IRTSession? // Having this IRTSession var causes a linker error
    
    override func didMove(to view: SKView) {
        // Using GameSparksRTSessionBuilder() causes a linker error
        session = GameSparksRTSessionBuilder().setConnectToken("TOKEN").setHost("HOST").setPort(4242).setListener(self).build()
    }
    
    func onPlayerConnect(_ peerId: NSNumber) {
        NSLog("onPlayerConnect: " + String(peerId as Int));
    }
    
    func onPlayerDisconnect(_ peerId: NSNumber) {
        NSLog("onPlayerDisconnect: " + String(peerId as Int));
    }
    
    func onReady(_ ready: Bool) {
        NSLog("onReady: " + String(ready));
    }
    
    func onPacket(_ packet: RTPacket) {
        // no errors thrown by using RTPacket as a parameter above. However, if I attempt to
        // use packet in this scope, I get an additional linker error
    }

    override func update(_ currentTime: TimeInterval) {
        // Called before each frame is rendered
        // update session here later
    }
}

   

While I don't expect the above code to behave appropriately at run time (since the sessionbuilder isn't configured with correct information), I expect this should at least build, yes?


Are there any project settings I need to change in order to use Real Time services from the iOS SDK?


Best Answer
Hello Theodore,
Yes, you're right and thus we have reverted our SDK to last stable version. Basically the RT module is written using C++ and Obj-C and it makes some troubles when users try to use it in Swift projects. So, you need to copy the RT folder from our public repository into the Shared (or any you want) folder of your project, then you have to create an Obj-C bridging header. You could have a look at our GSRTExamples folder to see how it works. Let us know whether now it is fine please.

Giuseppe

 Hey Theodore,


Have you got this https://bitbucket.org/gamesparks/gamesparks-ios-sdk/src/c0b03eb76f7afc3672f44004b81b5b382c58717e/GSRT.mm?at=master&fileviewer=file-view-default added to your project? If you're using pods, it isnt automatically added.


Cheers,

Omar

Hi Omar, thanks for the reply.


You are right, it looks like this implementation file wasn't included. Why isn't this file included using pods? 


Anyways, I tried dragging it into the project where the other GS files are (under pods/GameSparks), but it looks like there are other things which GSRT.mm references which are also not included using pods (like "GameSparksRT.hpp"), and of course these files include others, etc. 


Is there a way to set Cocoapods up to grab everything I need? Alternatively, what steps should I take to manually install the realtime components having used pods to install the regular SDK? (Or, if its easier: what steps should I take to install the whole SDK manually without the use of pods, to be able to access RT components?)

It looks like an update to the iOS SDK podspec file went live a couple hours ago, and it now appears to include the GSRT.mm file by default. 


However, this breaks the library due to requirements in GSRT.mm like:

 

#include "../../../../base/include/GameSparksRT/GameSparksRT.hpp"

 The above line results in a file not found build time error.

Hello Theodore,
We are still looking at this issue and it will be fixed as soon as possible.

Thanks,
Giuseppe

 

Hi Theodore,
We have done some fixes and could you tell us whether now it works for you, please?

Thanks,
Giuseppe

 

Sure thing. I encountered 4 new compiler errors using the most recent build. Here the steps I took and the errors I encountered.


Steps:

1. Create new iOS SpriteKit game template project in Xcode (Swift selected as language)

2. Import the most recent GameSparks API using CocoaPods.


At this point, the project actually built fine, until I used a "import GameSparks" line near the top of one of my swift files (my template's GameScene file to be exact.) After including this import statement, my project flagged 4 errors. These were the errors:


Errors:

1. Could not build Objective-C module 'GameSparks'

2. Unknown type name 'namespace' (in Forwards.hpp)

3. Expected ';' after top level declarator (in Forwards.hpp)

4. '../../include/GameSparksRT/Forwards.hpp' file not found (in GameSparksRT.hpp)


Does it do the same for you when importing the library using cocoapods in a normal swift spritekit template project?

Answer
Hello Theodore,
Yes, you're right and thus we have reverted our SDK to last stable version. Basically the RT module is written using C++ and Obj-C and it makes some troubles when users try to use it in Swift projects. So, you need to copy the RT folder from our public repository into the Shared (or any you want) folder of your project, then you have to create an Obj-C bridging header. You could have a look at our GSRTExamples folder to see how it works. Let us know whether now it is fine please.

Giuseppe

Hi Giuseppe,


Yes, this seems to work. Thanks for the help! 


A suggestion: under the installation section for the iOS SDK on Bitbucket, you might want to write a note informing people who want to use the RT components that they need to import the RT folder manually, make the bridging header, and import "GSRT.h" in the bridging header.


Anyways, thanks again!

Login to post a comment