This is my server implementation for my C++ corba server.
I have an idl file called blackjack.idl that generates blackjack.h and blackjack.cc when i compile it with mico command
$ idl --poa blackjack.idl
then i compile blackjack.cc with
$ mico-c++ -I. -c blackjack.cc -o blackjack.o
then compiling the code i have linked down in this topic with
$ mico-c++ -I. -c ServerHandler.cpp -o ServerHandler.o
this brings me no errors on one of my computers, but gives some warnings on the other one.
the problem arises when i try to compile the .o files together into an executable with this command:
$ mico-ld blackjack.o ServerHandler.o -o serverr -lmico2.3.12
Then i get the following error for ServerHandler:
ServerHandler.o:ServerHandler.cpp:(.text+0x785): undefined reference to `CosNaming::NamingContext::_narrow(CORBA::Object*)'
collect2: ld returned 1 exit status |
which is pretty weird since ServerHandler compilation doesnt produce any errors
The commands listed above are from a guide from my course teacher.
Ive spent a lot of time looking at CosNaming implementation aswell and basically it has 2 files CosNaming.idl and CosNaming.h . I tried compiling the idl file to produce an implementation for Cosnaming.cc, still got the same error.
Please, help me, I've been stuck on that error for almost 2 days now and the deadline keeps getting closer :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include "blackjack.h"
#include <pthread.h>
#include <iostream>
#include <unistd.h>
#include <CORBA.h>
#include <C:/Users/Feanor306/Desktop/mico/mico/include/coss/CosNaming.h>
// #include <C:/Users/Feanor306/Desktop/mico/mico/include/coss/CosNaming.cc>
using namespace std;
class ServerImpl: virtual public POA_Server {
private:
//vector<string> clients;
int betSum;
public:
ServerImpl();
~ServerImpl();
virtual CORBA::Boolean addUser(const char* username);
//void removeUser(string username);
//void addBet(long bet);
virtual long getCards(long temp);
};
ServerImpl::ServerImpl() {betSum = 0;}
ServerImpl::~ServerImpl() {
//for(std::vector<string>::iterator i = clients.begin(); i != clients.end(); i++ )
// delete(*i);
}
CORBA::Boolean ServerImpl::addUser(const char* usernam){
string username = usernam;
//clients.push_back(username);
return true;
}
/*void ServerImpl::removeUser(string username){
for(vector<string>::iterator it = clients.begin(); it != clients.end(); it++){
if(it==username){
delete (*it);
}
}
}*/
//void ServerImpl::addBet(long bet){
///betSum = betSum + bet;
//return true;}
long ServerImpl::getCards(long test){
return 1;
}
int main(int argc, char **argv) {
// Init ORB
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
// Init POA
CORBA::Object_var poaobj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaobj);
CORBA::PolicyList policies;
policies.length(1);
policies[0] = rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
// Get the POA manager object
PortableServer::POAManager_var manager = rootPOA->the_POAManager();
// Create a new POA with specified policies
PortableServer::POA_var myPOA = rootPOA->create_POA("myPOA", manager, policies);
// Get a reference to the Naming Service root_context
//CORBA::Object_var rootContextObj = orb->resolve_initial_references("NameService");
// Narrow to the correct type
CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(orb->resolve_initial_references("NameService"));
// Create a reference to the servant
ServerImpl* sImpl = new ServerImpl();
// Activate object
PortableServer::ObjectId_var myObjID = myPOA->activate_object(sImpl);
// Get a CORBA reference with the POA through the servant
CORBA::Object_var o = myPOA->servant_to_reference(sImpl);
// Get a reference to the CaesarAlgorithm interface
Server_var cav = Server::_narrow(o);
// The reference is converted to a character string
CORBA::String_var s = orb->object_to_string(cav);
cout << "The IOR of the object is: " << s << endl;
CosNaming::Name name;
name.length(1);
name[0].id = (const char *) "BJServer";
name[0].kind = (const char *) "";
// Bind the object into the name service
nc->rebind(name,o);
// Activate the POA
manager->activate();
cout << "The server is ready. Awaiting for incoming requests..." << endl;
// Start the ORB
orb -> run();
/*/ Write reference to file
ofstream of("chess");
CORBA::Object_var ref = poa->id_to_reference(oid.in());
CORBA::String_var str = orb->object_to_string(ref.in());
of << str.in() << endl;
of.close();*/
pthread_exit(0);
return 0;
}
|