Knock knock

IBM: Knock knock
User: Who’s there?
IBM: MQ
User: MQ who?
IBM: IBM MQ Client for macOS

In case you didn’t hear, IBM has released “IBM MQ macOS toolkit for developers” a couple of days ago.

I downloaded and installed it. I simply uncompressed it into my home directory. I played around with a bunch of commands (dspmqver, amqsputc, amqgetc, etc.) and everything worked as expected for an MQ client install.

I do C and Java development on a whole variety of platforms: AIX, HP-UX, Linux, IBM i (OS/400), Solaris, Windows and z/OS. I’ve only ever done Java development on macOS, so I thought I would have some fun and compile & link some C samples on macOS.

I did some internet searches and people said that you can use a Linux makefile with some tweaks on macOS. So, I copied the amqsput0.c and amsget0.c from a Linux server and also copied over a makefile I have on a Linux server to my macOS. After a couple of tweaks, I got it to compile and link those 2 MQ sample files.

Here is the makefile I used:

#
# makefile for MQ applications on macOS
#
CC = clang
CFLAGS = -std=c99 -pedantic -Wall

MQINSTALLPATH = $(HOME)/IBM-MQ-Client-Mac-x64-9.1.1.0
MQINC = -I$(MQINSTALLPATH)/inc
MQLIBPATH64 = -L$(MQINSTALLPATH)/lib64
MQLIB = -lmqic_r

all: amqsgetc amqsputc

amqsget0.o: amqsget0.c
	$(CC) $(CFLAGS) $(MQINC) -c amqsget0.c

amqsgetc: amqsget0.o
	$(CC) amqsget0.o -o amqsget0 $(MQLIBPATH64) $(MQLIB)

amqsput0.o: amqsput0.c
	$(CC) $(CFLAGS) $(MQINC) -c amqsput0.c

amqsputc: amqsput0.o
	$(CC) amqsput0.o -o amqsput0 $(MQLIBPATH64) $(MQLIB)

clean:
	rm -f *.o amqsgetc amqsputc

When I tried to run either of the 2 programs, I got the following error:

dyld: Library not loaded: @rpath/libmqic_r.dylib

After a few internet searches, I discovered that I needed to set DYLD_LIBRARY_PATH environment variable. It is like LD_LIBRARY_PATH on Linux.

export DYLD_LIBRARY_PATH=$HOME/IBM-MQ-Client-Mac-x64-9.1.1.0/lib64

When I did that, then everything worked as expected.

Now for those that are paying attention, the first question should be, how did the amqsputc and amqsgetc that were included in the {MQ_INSTALL_DIR}/samp/bin/ directory work? It is because the IBM developer who compiled & linked those MQ samples explicitly set the “rpath” linker setting. Since they control where the dynamic libraries are in relation to the MQ samples, they simply set rpath as “../../lib64/”.

If you want to do the same then your makefile will look like:

#
# makefile for MQ applications on macOS
#
CC = clang
CFLAGS = -std=c99 -pedantic -Wall

MQINSTALLPATH = $(HOME)/IBM-MQ-Client-Mac-x64-9.1.1.0
MQINC = -I$(MQINSTALLPATH)/inc
MQLIBPATH64 = -L$(MQINSTALLPATH)/lib64
MQLIB = -lmqic_r

RTL64 = -Wl,-rpath,$(MQINSTALLPATH)/lib64

all: amqsgetc amqsputc

amqsget0.o: amqsget0.c
	$(CC) $(CFLAGS) $(MQINC) -c amqsget0.c

amqsgetc: amqsget0.o
	$(CC) amqsget0.o -o amqsget0 $(MQLIBPATH64) $(MQLIB) $(RTL64)

amqsput0.o: amqsput0.c
	$(CC) $(CFLAGS) $(MQINC) -c amqsput0.c

amqsputc: amqsput0.o
	$(CC) amqsput0.o -o amqsput0 $(MQLIBPATH64) $(MQLIB) $(RTL64)

clean:
	rm -f *.o amqsgetc amqsputc

I don’t recommend you do this unless you have tight control over where the MQ Client installation will be located. I think it is easier to simply set the DYLD_LIBRARY_PATH environment variable.

Regards,
Roger Lacroix
Capitalware Inc.

This entry was posted in C, IBM MQ, macOS (Mac OS X), Programming.

Comments are closed.