0

I am writing a simple server program using ICE by ZeroC. When I try to link the .o files it gave me the following error message:

$ c++ -o server UserMap.o Server.o -L/Library/Developer/Ice-3.5.0/lib -lIce -lIceUtil
Undefined symbols for architecture x86_64:
  "VTT for UserMapI", referenced from:
      UserMapI::UserMapI() in Server.o
  "vtable for UserMapI", referenced from:
      UserMapI::UserMapI() in Server.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

After some googling I understand that the problem is I have an abstract class with 3 virtual methods declared in UserMap.ice (and hence in UserMap.h and UserMap.cpp generated by the command slice2cpp UserMap.ice), and in Server.cpp I have a class called UserMapI:public UserMap which implements the three virtual methods and another private helper function. The error is generated because the compiler thinks I have declared all functions(methods) in UserMap.h and UserMap.cpp.

My understanding to this problem is that I should modify the link command so that the linker will know that there are more functions in UserMapI declared in Server.cpp, but I don't have enough knowledge to do the modification. Can someone help me please?

Thank you all.


Here is the compiler command I am using to get Server.o and UserMap.o:

c++ -I. -I/Library/Developer/Ice-3.5.0/include -c UserMap.cpp Server.cpp

Here's the code of UserMap.ice:

module DR
{
    class UserMap
    {
        void addUserToLocation(int userID, int x, int y);
        string getUsersNearLocation(int x, int y, int distance);
        void removeFromMap(int userID, int x, int y);
    };
};  

slice2cpp command slices this .ice file into a .h and a .cpp file that works as an API between server and client.

In Server.cpp I have the following include:

#include <Ice/Ice.h>
#include "UserMap.h"

#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>

and the following subclass:

class UserMapI : public UserMap
{
public:
    virtual void addUserToLocation(int userID, int x, int y, const Ice::Current &);
    virtual string getUsersNearLocation(int x, int y, int distance, const Ice::Current &);
    virtual void removeFromMap(int userID, int x, int y, const Ice::Current &);
private:
    string stringify(int x, int y);
};

And after implementing all methods here's the main function:

int main(int argc, char* argv[])
{
    int status = 0;
    Ice::CommunicatorPtr ic;
    try {
        ic = Ice::initialize(argc, argv);
        Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("SimpleUserMapAdapter", "default -p 10000");
        Ice::ObjectPtr object = new UserMapI;
        adapter->add(object, ic->stringToIdentity("SimpleUserMap"));
        adapter->activate();
        ic->waitForShutdown();
    } catch (const Ice::Exception & e) {
        cerr << e << endl;
        status = 1;
    } catch (const char * msg) {
        cerr << msg << endl;
        status = 1;
    }
    if (ic){
        try {
            ic->destroy();
        } catch (const Ice::Exception & e) {
            cerr << e << endl;
            status = 1;
        }
    }
    return status;
}

Here's the UserMap.h.

Tengyu Liu
  • 1,223
  • 2
  • 15
  • 36
  • Can you post the code. Only the structure will be helpful – Aman Deep Gautam Jul 14 '13 at 01:58
  • I have posted some of the code. I hope that this will help. – Tengyu Liu Jul 14 '13 at 02:47
  • I am not entirely sure of this but as I see you inherit from `UserMapI` from `userMap` class and `userMap` class does not have those functions as virtual. – Aman Deep Gautam Jul 14 '13 at 03:51
  • ya the userMap class is defined in a `.ice` file, it is then sliced into a `.h` and a `.cpp` file. The slicing creates internet friendly api and all methods in the `.h` and `.cpp` are then virtual. Basically the resultant `UserMap.cpp` has those functions as virtual. – Tengyu Liu Jul 14 '13 at 03:56
  • Can you show what the generated `UserMap.h` looks like? – greatwolf Jul 14 '13 at 04:11
  • I wish I could but it is too long to be posted here. Is there a place I could post the code other than pastebin.com? I can't access pastebin from China. T_T – Tengyu Liu Jul 14 '13 at 04:40
  • 1
    @greatwolf Here's the link to the [file](https://github.com/oxrider/DR-for-help/blob/master/Documents/TryDRServer/UserMap.h). – Tengyu Liu Jul 14 '13 at 05:01
  • There seems to be several `UserMap` classes in differing namespaces. Which one does your `UserMapI` inherit from? – greatwolf Jul 14 '13 at 05:10

0 Answers0