I had a simple make file for an MQ program but it did not work, and I could not find any hints on how to get it to work.
cparms = -Wno-write-strings
clibs = -I. -I../inc -I’/usr/include’ -I’/opt/mqm/inc’
lparms = -L /opt/mqm/lib64 -Wl,-rpath=/opt/mqm/lib64 -Wl,-rpath=/usr/lib64 -lmqm
% : %.c
gcc -m64 $(cparms) $(clibs) $(lparms) $< -o $@
make mqcmd gave me
... undefined reference to
‘MQCONN’
... undefined reference to
‘MQOPEN’... undefined reference to
‘MQPUT’
... undefined reference to
MQCLOSE’... undefined reference to
‘MQDISC
collect2: error: ld returned 1 exit status
makefile:5: recipe for target ‘mqcmd’ failed
I moved the -lmqm to the end of the line
cparms = -Wno-write-strings
clibs = -I. -I../inc -I’/usr/include’ -I’/opt/mqm/inc’
lparms = -L /opt/mqm/lib64 -Wl,-rpath=/opt/mqm/lib64 -Wl,-rpath=/usr/lib64 -lmqm
% : %.c
gcc -m64 $(cparms) $(clibs) $< -o $@ $(lparms)
And it worked! I later found an entry in a blog post saying the -l...
directives are supposed to go after the objects that reference those symbols.
The IBM knowledge center is not very helpful. Under Building 64 bit applications, it has definitions for
- C client application, 64-bit, non-threaded
- C server application, 64-bit, non-threaded
- …
My problem is that I am writing a program which is a client as in client – server, running in bindings mode, which does a request reply to a server.
I think where the documentation says “C server” it means “C bindings mode”.
One thought on ““Make not working” due to order of link statements”