|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Strange linking error |
« View previous topic :: View next topic » |
Author |
Message
|
HenriqueS |
Posted: Tue Sep 04, 2007 2:25 pm Post subject: Strange linking error |
|
|
 Master
Joined: 22 Sep 2006 Posts: 235
|
(hummm...new fancy forum skin)...
Well folks, I am having some trouble compiling my first MQ Exit using Eclipse+CDT (it´s a C/C++ plug-in).
Basically it´s a server exit. When I used only the constants from the include files everything seemed ok, but the moment I started using MQ primitives that are stored on MQM.lib I started having the output below:
Plataform: Windows XP pro with
Code: |
$ uname -a
CYGWIN_NT-5.1 w2691361 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin
$ gcc --version
gcc (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
|
Code: |
**** Build of configuration Debug for project MQExit ****
make -k all
Building file: ../MQExit.c
Invoking: GCC C Compiler
gcc -I"C:\Arquivos de programas\IBM\WebSphere MQ\Tools\c\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"MQExit.d" -MT"MQExit.d" -o"MQExit.o" "../MQExit.c"
(several warnings go here, but compile seems successfull.)
Finished building: ../MQExit.c
Building target: MQExit.dll
Invoking: GCC C Linker
gcc -L"C:\Arquivos de programas\IBM\WebSphere MQ\Tools\Lib" -shared -o"MQExit.dll" ./MQExit.o -lmqm
Cannot export MQM_NULL_THUNK_DATA: symbol not found
collect2: ld returned 1 exit status
make: *** [MQExit.dll] Error 1
make: Target `all' not remade because of errors.
Build complete for project MQExit
|
I checked on the web what MQM_NULL_THUNK_DATA is...nothing, 'nada', 'niente' results on Google...(how lucky I am)
Proabably there is some issue between the linker and mqm.lib...but what? _________________ HenriqueS
Certified Websphere MQ 6.0 System Administrator |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Sep 04, 2007 8:48 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Hi,
gcc on Windows is not supported by IBM.
I would suggest that you go get the free Visual C++ Express from Microsoft. You can still use Eclipse and makefiles if you want.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
HenriqueS |
Posted: Thu Sep 06, 2007 1:22 pm Post subject: |
|
|
 Master
Joined: 22 Sep 2006 Posts: 235
|
Thanks Lacroix, in fact I wrote the article below, so any lost soul on the net may find it someday. Do the corrections as you wish.
SMALL ARTICLE ON COMPILING MQ - C PROGRAMS WITH UNSUPPORTED COMPILERS BY IBM
Platform: WebsphereMQ 6.0 Windows + cygwin/gcc
First, I want to thank Lacroix for opening my eyes. I´ve been browsing through the net the last days I´ve seen dozens of posts about people struggling to get linked C programs that make MQ calls.
Second, for the smart people, who don´t want to lose time, IBM has a list of supported compilers at http://www-1.ibm.com/support/docview.wss?rs=171&uid=swg27006266 . See? Cygwin, MinGw, Borland, etc. are NOT THERE.
Therefore, if you are smart enough, you can go directly to p://msdn2.microsoft.com/en-us/express/future/bb421473.aspx and download a beta version of Visual C++ Express 2008, or search the 2003 (previous version) on the Microsoft website. It is a free product.
Now, if you are not satisfied and are jealous you can keep trying to stick with gcc + cygwin or other C compiler, I will give below some hints, but to this moment, I only got the following working:
a) Plain C programs (mqm.lib) that make server-side MQ calls are compiled, linked and run fine.
b) C "MQ server exit" (mqm.lib) programs that are called by MQ are compiled, linked BUT DO NOT RUN.
c) MQ client exit programs (mqic32.lib) - don´t ask me...
Personally, I thinking that C compiling/linking is an area were many colleges fault on giving the proper teaching to their studentes. Too many people used to IDEs...
FIRST SCENARIO - PLAIN C PROGRAMS THAT MAKE SERVER-SIDE MQ CALLS:
Ok, you´ve got your source that compiles nice with your compiler, but you run it, so the fastest way you can do is (LINKING ONLY):
gcc -o output.exe output.o ../../Lib/mqm.lib
Hints:
1) Include the following #defines in your C program for the gcc family, or else it won´t even compile:
#ifndef _int64
#define _int64 long long
#endif
2) if using the -l parameter to indicate the impor tlibrary on the gcc compiler, you should not include the file extension. Here is a killer command line that compiles your program referencing the correct includes and libs:
gcc -o amqsput0.exe amqsput0.c -I ../Include -L ../../Lib -lmqm
As you may notice, the source program is on the "WebSphere MQ\Tools\c\Samples" dir provided by the MQ install. And please don´t forget to add the #defines written above in the top of the C source.
SECOND SCENARIO - C SERVER EXIT PROGRAMS THAT ARE CALLED BY MQ:
I have no real idea why I wrote this, because it gets you to a point where the thing just does not work. BUT I see some teaching value and may help someone getting to success someday and help those having problems on the FIRST SCENARIO. So please enter in contact posting a private messaging for me in the excellent mqseries.net forum.
The main complaint I´ve in the forums is about the linking step, which does not succeed. The fact is that most people think that Windows shared libraries are identified by a ".dll" extension and that any program can call their stored functions during runtime (look for dlopen() on the net) or even linked against your source/object file.
Surprisingly, this is not quite true. Even though DLLs are pretty much a standard (in terms of binary format and use/access), many issues arise when you start dealing with different linkers, cross-plataform toolkits (cygwin applies here) and import libraries.
Many people notice .lib extensions and have no clue for what they are. They are import libraries, or as far I got to understand, they just point to a real DLL and provided some auxiliary data to fool the linker, and your program must be linked against it to function properly.
But again, this is a so messed area, that you may find .libs that "point" to a .dll (import library) and .libs that are independent, not working as a pointer/bridge, but as a whole library itself (known as static library). Websphere MQ libs are in the first case. By example, the "WebSphere MQ\Tools\Lib\mqm.lib" file is the import library that must be used for linking and that, at the very end, points the application to use the functions provided on the "WebSphere MQ\bin\mqm.dll" file . Sure, I guess that mqm.dll depends on several other components...
Things get worse when you try to link your program against the import library as MQ enforces (never tried to link directly against "WebSphere MQ\bin\mqm.dll", if somebody can do that please write me). The fact is that import library format are compiler dependent and not every linker will grasp a import lib that was produces by another toolkit. So, you´ve got a .lib that was probably built with Visual C++ and you are trying to use it on another linker.
The usual consequence is a lot of symbol errors when linking because some function names have "decoration" - extra chars (usually a suffix with a '@') that are only understood by the Visual C++ linker to refer to a library function.
The hardcore approach is to export the symbols from the import lib into a text file (called DEFinition file), rename what is needed (sometimes renaming is not needed), pack them onto a new import lib on which your linker can understand and link the application. Easy, huh?
There is am excellent tutorial on this issue called "A Moron's Guide to Using Microsoft DLL's when Compiling Cygwin or Mingw Programs" at:
http://www.emmestech.com/software/cygwin/pexports-0.43/moron1.html
What are the tools needed? They vary according to the C toolkit...some names below:
1) Export/extract symbols from an import library: pedump, exp, pexport, reimp.
2) To edit the defition file: any text file editor...
2) To pack the modified defition file into a new lib: implib, impdef, dlltool.
Remember that when putting your newly generated (and compatible) lib into a directory, that the gcc linker has a seach order. By example, the usual install of MQ already provides mqm.lib, right? So your new lib import file must be found before it. Talking about cygwin, you may find at http://sourceware.org/binutils/docs-2.15/ld/WIN32.html the search order when you specify "-lxxx":
libxxx.dll.a
xxx.dll.a
libxxx.a
xxx.lib
cygxxx.dll (*)
libxxx.dll
xxx.dll
*The last three file patterns mean the use of direct-DLL linking without use of an import library. So I guess the ld manual has some good pointer to help someone trying to link directly to mqm.dll .
I found this remarkable piece on the net, where I got most of the stuff I rewrote here and summarizes the subject:
Quote: |
What you really have to understand when trying to use these .lib files is not about filenames or file formats or making .def files or any of that. All you really need to determine is:
1) what calling convention (cdecl or stdcall) does the library use, and
2) how are the symbol names decorated?
Then just make these match with your toolchain. Usually the two are related, but they are really separate concepts.
For (1) you have to get your headers right.
For (2) you create an import library that contains the necessary aliases, or if your compiler already uses the same decorations as the library, you can just link against the DLL directly without an import lib at all.
|
Last, for the lazy ones, the steps I made for a sucessfull link of my MQ Exit (remember: using the cygwin-gcc toolkit, dont´ask me about others):
Code: |
pexports mqm.dll | sed 's/^_//' > mqm.def
dlltool --input-def mqm.def --dllname mqm.dll --output-lib libmqm.a
ranlib libmqm.a
gcc -L"C:\Program files\IBM\WebSphere MQ\Tools\Lib" -shared -o"MQExit.dll" ./MQExit.o -lmqm
|
Don´t forget to configure the channel!
Code: |
DEFINE CHANNEL ... + CHLTYPE(SDR/...) + MSGEXIT('MY_DLL(MsgExit)')
|
Hints:
1) Where the MY_DLL stays on the "WebSphere MQ\exits" dir.
2) Do not include the ".dll" suffix.
3) MsgExit is the function name on the source "MQENTRY MsgExit(..){...}".
In my very particular case, things did not work here, as the MQ trace details:
Code: |
0003F147 19:48:58.110000 4552.1 Handle(00000000) Function(00000000) FullPathLibName(C:\temp\MQExit.dll)
0003F148 19:48:58.110000 4552.1 ------}! xcsLoadFunction (rc=xecU_S_LOAD_FAILED)
0003F149 19:48:58.110000 4552.1 ------{ rrxError
0003F14A 19:48:58.110000 4552.1 RetCode = 20009535, rc1 = 536895861, rc2 = 0, Comment1 = 'CLIENT.TO.EXAMPLES', Comment2 = 'C:\temp\MQExit(MsgExit)', Comment3= '', File= 'F:\Build\p000_P\src\lib\client\amqrexta.c', Line= '5253'
|
In contact with an IBM Engineer, he told me: "Try a supported compiler".
Did did you get the point? Go back to the very beggining of the article...
Tomorrow is independence day in my country, so see you guys next week.  _________________ HenriqueS
Certified Websphere MQ 6.0 System Administrator |
|
Back to top |
|
 |
HenriqueS |
Posted: Tue Sep 18, 2007 1:19 pm Post subject: |
|
|
 Master
Joined: 22 Sep 2006 Posts: 235
|
*** UPDATE ***
MINGW´s GCC produces 100% working exit dlls!
Folks, I´ve tried the last week the Mingw toolchain and it seems to produce dlls that are sucessfully compiled by its GCC port.
Sample command line:
Code: |
c:\mingw\bin\gcc -I"C:\Arquivos de programas\IBM\WebSphere MQ\Tools\c\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"MQExit.d" -MT"MQExit.d" -o"MQExit.o" "MQExit.c"
c:\mingw\bin\gcc -L"C:\Arquivos de programas\IBM\WebSphere MQ\Tools\Lib" -shared -o"MQExit.dll" ./MQExit.o -lmqm
|
*gcc´s above cmd line uses -o0 and -g3 but replace this by -03 and -g0 for a real environment.
Don´t forget to produce a linkable import library for gcc using perxports and dlltool as described above... |
|
Back to top |
|
 |
RogerLacroix |
Posted: Wed Sep 19, 2007 9:24 am Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
HenriqueS wrote: |
MINGW´s GCC produces 100% working exit dlls!
|
Yes as long as you remember that IBM does not support it. Hence, you cannot open a PMR to report any problems.
I've watched your progress and the interesting path you have taken.
4-5 years ago, I went down that same path. I wanted to use GCC on several platforms because it would be my 'standard' compiler. What I learnt was that there was very little in GCC that was common between Windows or Solaris or AIX or HP-UX or Linux, etc...
Worst was when I encounter a problem and tried to report it I got the big hand from IBM saying that the compiler was unsupported.
Back in 2005, I finally gave up on my 'GCC everywhere' project and went back to standard native support compilers.
I haven't posted info on Windows GCC makefile as I spent many, many hours figuring it out and I considered it my proprietary information.
But seeing how you have most of the pieces, I'll give you a makefile that will make it even simpier.
So lets say you want to compile the dummy.c security exit from this link:
http://www.mqseries.net/phpBB2/viewtopic.php?t=21782
Create a makefile called: makefile.gcc.nt and put the following commands in it:
Code: |
# This Makefile makes the dummy security exit
#
all: dummy.dll
# CC defines the compiler.
CC = gcc
DLLWRAP= dllwrap
# Set CCOPTS - the compiler options.
CCOPTS = -c -DMINGW32
# MQM directories
MQMLIB = "C:\Program Files\IBM\WebSphere MQ\Tools\Lib"
MQMINC = "C:\Program Files\IBM\WebSphere MQ\Tools\c\include"
DLLMQLIBS = -lm -lmqm -lwinmm
### -----------------------------------------------------------------
dummy.dll : dummy.o
$(CC) -shared -mthreads -o dummy.dll dummy.o -L$(MQMLIB) $(DLLMQLIBS)
$(DLLWRAP) --export-all --output-def=libdummy.def --output-lib=libdummy.a --dllname=dummy.dll dummy.o -L$(MQMLIB) $(DLLMQLIBS)
$(CC) -shared -Wl,--enable-auto-image-base -o dummy.dll -Wl,--out-implib=libdummy.a dummy.o -L$(MQMLIB) $(DLLMQLIBS)
### -----------------------------------------------------------------
dummy.o : dummy.c
### -----------------------------------------------------------------
#the object files depend on the corresponding source files
.c.o:
$(CC) $(CCOPTS) -I. -I$(MQMINC) $<
clean:
del *.exe *.o *.res *.dll |
You do not need to create an export file as this makefile will create it for you.
If you have MinGW installed and the PATH environment variable has been updated then you can simply do:
Code: |
mingw32-make -f makefile.gcc.nt |
And it will completely build your Windows Security Exit DLL.
Enjoy.
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
grabeva |
Posted: Tue Jul 01, 2008 8:10 am Post subject: |
|
|
Newbie
Joined: 12 Jun 2007 Posts: 6 Location: argentina
|
Good moorning.....
My name is Grace, from Argentina.
I need help....!!!!
I no have expirience from development with C,
i know MQSeries.
I have a source program C, that i want to compile and generate a DLL.
I read this forum and i find several products to compile C.
but a dont understand....who is the compile quite simple and with GU for windows?
or if someone give me the manner to compile with (VB6 or Visual studio .NET) and DLL with MQSeries....?????
thanks for your time.....
and sorry for my english) |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|