9 Replies Latest reply on Mar 4, 2015 4:00 PM by Chris Child

    Native Extension Example

    Chris Child

      Hello,

       

      I'm trying to complete the example for Native Extensions Rhomobile | Building a native extension.

       

      I'm getting the error below and I'm not quite sure why. From googling some have said it is because I have not implemented all the other members of the abstract class but why would it be complaining specifically about the welcome method? Has anyone successfully completed the Greeting example on the Native Extensions page?

       

      Just a note I'm trying to build for Win32 and I get this error.

       

      src\Greeting_impl.cpp(55) : error C2259: 'rho::CGreetingSingleton' : cannot instantiate abstract class due to following members:

              'void rho::IGreetingSingleton::welcome(const rho::String &,rho::apiGenerator::CMethodResult &)' : is abstract

        • Re: Native Extension Example
          Jon Tara

          The welcome method is the only method that your example extension has! (Other than standard base methods.)

           

          Did you add an implementation in Greeting_impl.cpp, as shown in the documentation?

           

          You have to add it yourself.

            • Re: Native Extension Example
              Chris Child

              Yes I have it implemented inside Greeting_impl.cpp.

               

              I have tried the code below which is a straight copy from the docs.

               

              class CGreetingSingleton: public CGreetingSingletonBase

              {

                  ~CGreetingSingleton(){}

                  public:

                      void welcome( const rho::String& user, rho::apiGenerator::CMethodResult& oResult) {

                          oResult.set("Welcome, "+user);

                      }

              };

                • Re: Native Extension Example
                  Jon Tara

                  In what directory? It has to be in /impl.

                   

                  /stub_impl files are just there for you to look at. They aren't used when you build the project.

                   

                  It will write some prototype code in files in /stub_impl and you have to manually copy the lines into files in /impl.

                   

                  It is a bit confusing!

                   

                  I just wrote an extension (actually, ported one that was written for Rhodes 3.x, and needed to go to new 4+ style for iOS 64-bit build) so it's pretty fresh in my mind! But I haven't written a Win32 extension, I've only implemented my extension for iOS. (It wouldn't make any sense for Win32, anyway, because my extension is dealing with virtual keyboard...)

                    • Re: Native Extension Example
                      Chris Child

                      Well that does make some more sense then why it would be complaining when the method is clearly implemented. I just double checked to make sure I didn't miss anything regarding making sure I add the code to /impl and there is no mention of it on the page I linked to in my original post. I also do not see any mention that I should have to delete the project and bin folders either. Where do I need to add the /impl folder to as it does not currently exist?

                       

                      Thanks for the help so far.

                        • Re: Native Extension Example
                          Jon Tara

                          Sorry, I didn't really mean /impl. I mean relative to the extension directory. Here, I'll show you a picture...

                           

                          Ooh, maybe I have led you astray. I wasn't familiar with the Win32 directory structure. You write that code in /qt, right?

                           

                          In any case, any code in a directory with "stub" as part of the directory name is NOT a part of the built app. It is just there for you to examine and copy (parts of).

                           

                          Also, any files in any directory called "generated" should not be modified. Those files will be re-created any time you change your XML API specification.

                           

                          Still, maybe this picture will help. At least then you can as questions about where things belong!

                           

                          extension.png

                          So, I only write for iOS, and so I am writing in CEE/ext/platform/iphone/impl.

                           

                          CEE/ext/platform/iphone/generated/stub_impl is not used at all. It is for looking at.

                           

                          CEE/ext/platform/generated/<anything> should not be changed.

                           

                          It looks like qt (Win32) has a different structure, though. It doesn't have all those directories! I think you should be writing in the highlighted file. Is that where you are writing?

                            • Re: Native Extension Example
                              Chris Child

                              I understand what you're talking about now. So I was told that the WM platform should work for Win32 so that is what I've been trying and it does not have a /impl directory. Instead the Greeting_impl.cpp is inside a src directory which is part of a Visual Studio 2008 project. The docs suggest that all you need to do is create the welcome method inside that cpp file and you should be good to go. I'm going to create a ticket with Rho as I think this is going to require their help.

                        • Re: Native Extension Example
                          Jon Tara

                          Also, make sure you just completely remove the /project directory before build. There is a note in the docs about that. I don't think that the extensions properly clean when you clean the overall project. So, the work-around is if you change the extension, you should do a clean build after just wiping-out /project. (And I guess you should remove /bin too.)

                           

                          What version are you using?

                          1 of 1 people found this helpful