Building and running the C++ apps
Our source files -- Hello.idl, server.cpp, and
client.cpp -- will port to NT and all the major Unix
platforms with nary a change. This is a benefit to using ACE &
TAO. I encourage you to build both versions and see how well the
different clients and servers play with each other, NT to Unix and
vice versa.
On any popular Unix platform, you should be able to do this:
- Ensure that ACE_ROOT and TAO_ROOT are set properly in your environment.
- Save these files to some local directory:
- Using the GNU version of make, go to that directory and type
'make'.
One of the most confusing aspects of ACE is its Makefile
structure. It is my hope that you can use the Makefile for this tutorial as a template.
Let's take a look at the sections you'll likely need to modify for your own applications.
The BIN target contains the name[s] of your executable
application[s]. Most often, there will only be one target: the
name of the file that contains your main routine,
stripped of the .cpp extension. As this example shows,
however, it's possible to have more than one BIN target.
# Ultimate executable targets
BIN = server client
Create a target for the object files with which your BIN target
must link. Because we have two BIN targets, we create an "object
files target" for each. Notice that TAO requires both client and
server applications to link with both the stubs and skeleton
classes generated by the IDL compiler. This is due to some
optimizations TAO provides for co-located CORBA objects (clients
and servants in the same address space). I consider this to be a
TAO idiosyncrasy.
# Object files required for server
SERVER_OBJS = \
HelloC.o \
HelloS.o \
server.o
# Object files required for client
CLIENT_OBJS = \
HelloC.o \
HelloS.o \
client.o
I think the following lines are necessary primarily for building
dependencies (with the command, 'make depend'), which you
won't be able to do successfully until after you've generated the
IDL stubs and skeletons, which will be done automatically for you
the first time you run make. In other words, run
'make' at least once before you run 'make depend'.
# Establish SRC target
IDL_SRC = HelloC.cpp HelloS.cpp
PROG_SRCS = client.cpp server.cpp
SRC = $(IDL_SRC) $(PROG_SRCS)
For each one of your BIN targets, add a dependency similar to the
following. Substitute the stuff highlighted in
red with stuff appropriate for your application.
# How to build server
server: $(addprefix $(VDIR),$(SERVER_OBJS))
$(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK)
# How to build client
client: $(addprefix $(VDIR),$(CLIENT_OBJS))
$(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK)
For the realclean target, substitute the basename of your
IDL file appropriately:
# Things to clean up
realclean: clean
-/bin/rm -rf HelloC.* HelloS.* HelloS_T.*
Of course, it's naive of me to think that's all you'll need to
change. Depending on your... er... dependencies, you may also need to
modify these (and possibly even other) targets:
- LDLIBS -- a list of external libraries with which to link
- LDFLAGS -- e.g. a list of directories specified with the -L
option in which to search for external libraries
- CPPFLAGS -- e.g. a list of directories specified with the
-I option in which to search for header files
To run the examples, first start the server and redirect its
output (its IOR) to a file. Then pass the contents of that file
as a parameter to the client, like so:
$ ./server > /tmp/ior &
[1] 10399
$ ./client `cat /tmp/ior`
World said "Greetings from C++ World server!!"
$ kill %1
[1]+ Terminated ./server >/tmp/ior
I used Developer Studio 97 with Visual C++ 5.0 to create a workspace containing two projects: one for
the client and one for the server. If you have a compatible IDE, you
should be able to do this:
- Ensure that ACE_ROOT and TAO_ROOT are set properly in your environment.
- Save these files to some local directory:
- Open hello.dsw in DevStudio and build both projects
-- that should create a Debug directory that contains,
among other things, server.exe and client.exe.
Easy, right? There are some important project settings required
by ACE and TAO that are probably worth mentioning here. You'll
need to know this stuff if you ever try to port some pre-existing
source code to DevStudio, as I did for this tutorial. (I'm
putting it here because I know I'll forget it later)
- Project type should probably be a Windows Console
Application.
- Remember to override the default location when creating new
workspaces and/or project -- it seems to want to create a
directory of the same name beneath the current one.
- Project Settings -> C/C++ -> Code Generation -> Use run-time
library -> Debug Multithreaded DLL
- Project Settings -> C/C++ -> Precompiled Headers -> Not
using precompiled headers
- Project Settings -> C/C++ -> Preprocessor -> Additional
include directories -> $(ACE_ROOT); $(TAO_ROOT)
- Project Settings -> Link -> General -> Object/library
modules -> $(ACE_ROOT)\ace\aced.lib $(TAO_ROOT)\tao\taod.lib
- Establish a "custom build step" for IDL files:
- Ensure that all IDL files have been added to all
projects.
- In the Project Settings dialog, choose All
Configurations in the "Settings For" drop down, and
select (ctrl-left-click) each IDL file in each project.
- Check Always use custom build step
- Click on the "Custom Build" tab and enter Compiling
IDL or some such drivel for the "Description".
- For the "Build command" enter
$(ACE_ROOT)\bin\tao_idl.exe $(InputName).idl
- For the "Output files" enter these:
- $(InputName)S.h
- $(InputName)C.h
- $(InputName)C.i
- $(InputName)C.cpp
- $(InputName)S.i
- $(InputName)S.cpp
- $(InputName)S_T.h
- $(InputName)S_T.i
- $(InputName)S_T.cpp
- Click OK
On NT, you'll of course want to make sure that the ACE/TAO DLL's
are accessible, i.e. in your PATH.
Running these programs on NT is much harder than one might expect,
especially when you consider how easy it is on
Unix. It wouldn't be so much of a pain if you could do either
of two things: pass the contents of a file as a parameter
on the command line (as backquotes allow you to do in Unix), or
copy multiple lines of text from an NT shell (cmd.exe)
without inserting a friggin' carriage return and line feed
between each line!!!
Oh, well. Here's one asinine way of doing it. I'm sure there
are others.
- Fire up a couple of NT shells and change the directory of
each to the Debug directory containing our executables.
- Run server.exe in one of the shells. Note that it
dumps its IOR to stdout. If you're lucky, the IOR will fit on
one line, but I doubt anyone is that lucky.
- In the other shell, type the word client followed
by a space. Don't hit the Enter key just yet.
- Go back to the "server shell" and open the System Menu
(either type Alt-space or click the top-left corner of the
title bar). Choose Edit and then Mark.
- Highlight the first "line" of the IOR (including the
beginning letters, IOR:). Hit the Enter key to copy
the text.
- Go back to the "client shell" and paste the line you copied
(System Menu, Edit, Paste). Don't hit
Enter yet!
- Repeat steps 4-6 for the remainder of the IOR. On each
iteration, try to come up with a new synonym for asinine.
Here are a few to get you started: stupid,
silly, idiotic, moronic,
imbecilic, and dim-witted. You get the idea?
- Now you can hit Enter in the "client shell".
There. That was worth it, wasn't it?
Back to... [ Corba Tutorials ]
Jim Crossley
Last modified: Fri Mar 26 20:32:05 EST 1999