Discussion:
Compilation problems
(too old to reply)
Naimad
2009-07-20 16:58:36 UTC
Permalink
Hi,

I'm trying to compilation my first program at Corba OmniORB.
I build file with idl:

interface Calc {
double Sum(in double a, in double b);
long Counter();
};

I build client file:

#include <iostream>
#include <iomanip>
#include "calc.hh"
using namespace std;
//-----------------------------------------------------------------------------

int
main(int argc, char * argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

// Check arguments
if (argc != 2) {
cerr << "Usage: client IOR_string" << endl;
throw 0;
}

// Destringify argv[1]
CORBA::Object_var obj = orb->string_to_object(argv[1]);
if (CORBA::is_nil(obj)) {
cerr << "Nil Time reference" << endl;
throw 0;
}

// Narrow
Calc_var calc= Calc::_narrow(obj);
if (CORBA::is_nil(calc)) {
cerr << "Argument is not a Time reference" << endl;
throw 0;
}

// Get time
cout << "2 + 3 = " << calc->Sum(2,3) << endl;
}
catch (const CORBA::Exception &) {
cerr << "Uncaught CORBA exception" << endl;
return 1;
}
catch (...) {
return 1;
}
return 0;
}

and I build server file:

#include <calc.h>
#include <iostream>
#include "calc.hh"
using namespace std;

class Calc_impl : virtual public Calc_skel {

private:
CORBA::Long __counter;
public:
Calc_impl() { __counter = 0; }
CORBA::Double Sum(CORBA::Double a, CORBA::Double b) { __counter++;
return a+b;}
};
//--------------------------------------------------------

int
main(int argc, char * argv[])
{
try {
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

// Get reference to Root POA.
CORBA::Object_var obj
= orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa
= PortableServer::POA::_narrow(obj);

// Activate POA manager
PortableServer::POAManager_var mgr
= poa->the_POAManager();
mgr->activate();

// Create an object
Calc_impl calc_servant;

// Write its stringified reference to stdout
Calc_var server = calc_servant._this();
CORBA::String_var str= orb->object_to_string(server);
cout << str << endl;

// Accept requests
orb->run();
}
catch (const CORBA::Exception &) {
cerr << "Uncaught CORBA exception" << endl;
return 1;
}
return 0;
}

With compilation calc.idl and client I don't have problems, but I have
problems with compilation server. At first I have many errors but now
I have only one or two. Here they are:

server.cc:1:18: error: calc.h: Nie ma takiego pliku ani katalogu
server.cc:6: error: expected class-name before ‘{’ token
server.cc: In function ‘int main(int, char**)’:
server.cc:38: error: ‘class Calc_impl’ has no member named ‘_this’
make: *** [server.o] Błąd 1

What is wrong?
This example I take from polish book about CORBA, but it was to MICO
CORBA. I tried to change it to OmniORB. For base I take example who
work at my Debian with OmniORB (I think you are know this example from
book "Advanced CORBA Programming with C++")

I am very grateful for your help. Sorry for my English but I still
learn it.
Lars Tetzlaff
2009-07-20 17:29:51 UTC
Permalink
Post by Naimad
server.cc:1:18: error: calc.h: Nie ma takiego pliku ani katalogu
If "Nie ma takiego pliku ani katalogu" means "no such file or directory"
then
1) you don't have any calc.h (is it called calc.hh?)
2) the include path is missing (-I ...)

Lars
Ciaran McHale
2009-07-20 21:12:56 UTC
Permalink
[compilation errors in a CORBA server]
class Calc_impl : virtual public Calc_skel {
You should inherit from "POA_Calc" instead of "Calc_skel".
I'm going to take an educated guess that the "Calc_skel"
class is generated by the IDL compiler to provide support
for legacy BOA-based applications. The BOA-based CORBA
specification predates the POA-based specification by
several years, and you should be using the POA-based
approach for writing new applications.

For learning about CORBA I would recommend first reading the "CORBA
Explained Simply" book that is available free-of-charge at my website
(www.CiaranMcHale.com). Of course, as the author, I am a bit biased
in recommending it:-) The book focuses on high-level CORBA concepts
rather than coding examples. After reading that, I'd recommend
"Pure CORBA" by Fintan Bolton for learning the programming details.
I'm not the least bit biased by the fact that Fintan and I used to
work together. His book is excellent.


Regards,
Ciaran.
--
Ciaran McHale, www.CiaranMcHale.com
Email: ciaran _ mchale @ yahoo . co . uk
Mobile: +44-(0)7866-416-134
Duncan Grisby
2009-07-21 11:01:10 UTC
Permalink
Post by Ciaran McHale
[compilation errors in a CORBA server]
class Calc_impl : virtual public Calc_skel {
You should inherit from "POA_Calc" instead of "Calc_skel".
I'm going to take an educated guess that the "Calc_skel"
class is generated by the IDL compiler to provide support
for legacy BOA-based applications. The BOA-based CORBA
specification predates the POA-based specification by
several years, and you should be using the POA-based
approach for writing new applications.
In fact, omniidl doesn't generate anything called Calc_skel, hence the
compiler error of "expected class-name before '{' token".

(As an aside, you can ask omniidl to generate skeletons using the old
omniORB BOA mapping, but that generates a class called _sk_Calc.)

Niamad, in addition to the resources Ciaran mentions, you might find
it useful to look at the examples in omniORB's src/examples directory,
and the first couple of chapters of the omniORB manual.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Naimad
2009-07-22 19:44:10 UTC
Permalink
Post by Duncan Grisby
Post by Ciaran McHale
[compilation errors in a CORBA server]
class Calc_impl : virtual public Calc_skel {
You should inherit from "POA_Calc" instead of "Calc_skel".
I'm going to take an educated guess that the "Calc_skel"
class is generated by the IDL compiler to provide support
for legacy BOA-based applications. The BOA-based CORBA
specification predates the POA-based specification by
several years, and you should be using the POA-based
approach for writing new applications.
In fact, omniidl doesn't generate anything called Calc_skel, hence the
compiler error of "expected class-name before '{' token".
(As an aside, you can ask omniidl to generate skeletons using the old
omniORB BOA mapping, but that generates a class called _sk_Calc.)
Niamad, in addition to the resources Ciaran mentions, you might find
it useful to look at the examples in omniORB's src/examples directory,
and the first couple of chapters of the omniORB manual.
Cheers,
Duncan.
--
 -- Duncan Grisby         --
   --http://www.grisby.org--
Thanks for your help. I will continue to be taught CORBA. It can help
deal with this problem.

Cheers,
Naimad

Loading...