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.

Building apps on Unix

On any popular Unix platform, you should be able to do this:
  1. Ensure that ACE_ROOT and TAO_ROOT are set properly in your environment.
  2. Save these files to some local directory:
  3. 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:

Running apps on Unix

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
	

Building apps on NT

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:
  1. Ensure that ACE_ROOT and TAO_ROOT are set properly in your environment.
  2. Save these files to some local directory:
  3. 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)

Running apps on NT

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.

  1. Fire up a couple of NT shells and change the directory of each to the Debug directory containing our executables.
  2. 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.
  3. In the other shell, type the word client followed by a space. Don't hit the Enter key just yet.
  4. 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.
  5. Highlight the first "line" of the IOR (including the beginning letters, IOR:). Hit the Enter key to copy the text.
  6. Go back to the "client shell" and paste the line you copied (System Menu, Edit, Paste). Don't hit Enter yet!
  7. 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?
  8. 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