I’ve come across an interesting tool for MQAdmins or MQ developers. It’s called C, Just in Time! (aka CJIT). It is available for Windows, macOS and Linux platforms. CJIT is written by Jaromil, Danielinux and Matteo, and inspired by Puria and Alvise.
CJIT is a lightweight C interpreter that lets you run C code instantly, without needing to build it first. Just use the executable interpreter: no extra tools, libs, or headers required. Based on Fabrice Bellard’s TinyCC and inspired by Terry Davis (HolyC), CJIT brings the power of Just-In-Time execution to C programming. 100% Free and open source!
First, I tried CJIT on a couple of “Hello World” type of C programs and it worked like a charm.
Next, I was thinking about how sometimes you want to make a small change to an IBM sample MQ program but you have to have a full-blown compiler/linker installed to rebuild the C source code. Installing MS Visual Studio is a beast and requires a fair bit of knowledge about what components the developer needs. Installing GCC on Windows is easier but still does require some knowledge. Plus what if the PC/laptop you are using is locked down and you cannot install software on it.
CJIT is a single executable that you do not need to install, you simply download it from here. Just create a directory called C:\CJIT and download CJIT into that directory, and now you are ready to go. It’s that simple.
The manpage for CJIT can be found here or you can run CJIT from the command prompt with the ‘-h’ parameter and you will see:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | C:\CJIT>cjit.exe -h
CJIT v0.16.2 by Dyne.org
Synopsis: cjit [options] files(*) -- app arguments
(*) can be any source (.c) or built object (dll, dylib, .so)
Options and values (+) mandatory (-) default (=) optional:
-h print this help
-v print version information
-q stay quiet and only print errors and output
-C set interpreter/compiler flags (-) env var CFLAGS
-c compile a single source file, do not execute
-o exe do not run, compile an executable (+path)
-D sym define a macro value (+) symbol or key=value
-I dir also search folder (+) dir for header files
-l lib link the shared library (+) lib
-L dir add folder (+) dir to library search paths
-e fun run starting from entry function (-) main
-p pid write execution process ID to (+) pid
--verb don't go quiet, verbose logs
--xass just extract runtime assets (=) to path
--xtgz extract all files in a USTAR (+) tar.gz
|
FYI: On Windows, the ‘-L’ parameter does not appear to work and I have reported to the author. The work around is to copy the DLL to the same directory as your source code.
Example: lets say you want to use the MQ sample called amqsbcg0.c but you want the BUFFERLENGTH define to be 200,000 rather than 65,536 but to make the change and rebuild the executable, you need a compiler/linker toolset. This is where CJIT can come in super handy and here’s how I tested it out with an IBM MQ sample C program.
I created a directory called C:\temp\MQ_src\ and copied the amqsbcg0.c source to it along with the mqm.dll from the D:\Program Files\IBM\MQ\bin64\ directory.
1 2 3 4 5 6 7 8 9 10 11 12 | C:\temp\MQ_src>dir
Volume in drive C is OS
Volume Serial Number is 76E7-6850
Directory of C:\temp\MQ_src
2025-02-19 05:01 PM <DIR> .
2025-02-19 05:00 PM <DIR> ..
2022-10-06 01:00 AM 44,727 amqsbcg0.c
2022-10-06 01:00 AM 47,592 mqm.dll
2 File(s) 92,319 bytes
2 Dir(s) 293,742,751,744 bytes free
|
Next, edit the amqsbcg0.c source and change whatever code in it you want to.
Next, I used MQ Visual Edit to put a simple test message on the queue ‘TEST.Q1’.
Next, it is time to BOTH compile/link AND run amqsbcg0.c sample program. CJIT requires that if your program requires parameters that you place 2 dashes and then the parameters for the program. Here is the command to do compile and run it browsing queue ‘TEST.Q1’ on queue manager ‘MQA1’:
1 | C:\CJIT\cjit.exe -I"D:\Program Files\IBM\MQ\tools\c\include" -lmqm amqsbcg0.c -- TEST.Q1 MQA1
|
Here is the output from amqsbcg0.c:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | CJIT v0.16.2 by Dyne.org
AMQSBCG0 - starts here
**********************
MQOPEN - 'TEST.Q1'
MQGET of message number 1, CompCode:0 Reason:0
****Message descriptor****
StrucId : 'MD ' Version : 2
Report : 0 MsgType : 8
Expiry : -1 Feedback : 0
Encoding : 273 CodedCharSetId : 819
Format : 'MQSTR '
Priority : 0 Persistence : 0
MsgId : X'414D51204D5157543120202020202020A0B5B36701620040'
CorrelId : X'000000000000000000000000000000000000000000000000'
BackoutCount : 0
ReplyToQ : ' '
ReplyToQMgr : 'MQA1 '
** Identity Context
UserIdentifier : 'rlacroix '
AccountingToken :
X'160105150000003200057246D646E7D52332D3E903000000000000000000000B'
ApplIdentityData : ' '
** Origin Context
PutApplType : '11'
PutApplName : 'mqve.exe '
PutDate : '20250219' PutTime : '22203689'
ApplOriginData : ' '
GroupId : X'000000000000000000000000000000000000000000000000'
MsgSeqNumber : '1'
Offset : '0'
MsgFlags : '0'
OriginalLength : '-1'
**** Message ****
length - 23 of 23 bytes
00000000: 5468 6973 2069 7320 6120 7465 7374 206D 'This is a test m'
00000010: 6573 7361 6765 2E 'essage. '
No more messages
MQCLOSE
MQDISC
|
The next test is to actually build an executable using CJIT and then run the executable by itself. To do that, use the following command:
1 | C:\CJIT\cjit.exe -I"D:\Program Files\IBM\MQ\tools\c\include" -lmqm amqsbcg0.c -o amqsbcg.exe
|
Now, anytime you want to run amqsbcg.exe with your changes, you just type:
1 | C:\temp\MQ_src>amqsbcg.exe TEST.Q1 MQA1
|
And you get the same output as above.
So now you have a quick and easy way to modify and test any C source code without needing a full blown C compiler/linker.
Regards,
Roger Lacroix
Capitalware Inc.