libdmtx Java Wrapper

1. Installing libdmtx-java on GNU/Linux

libdmtx does not need to be installed system-wide to build the Java wrapper, but it does need to be compiled in the grandparent directory. If using the "make" command, this and other prerequisites will be met simply by running:

$ make

To build and run the test programs:

$ make check
$ javac
$ java GUIExample <path to a PNG image file>

If your system runs SELinux then you may need to either switch to Permissive mode, disable it entirely, or assign a security context that allows Java to load the native/ library. If you are an SELinux guru, please add a comment here (click the "edit" link below) on the proper method to handle this situation so we can improve the package (e.g., Install program? chcon command?)

2. Installing libdmtx-java on Windows

Assuming that you have followed all of the instructions for compiling the main code in Windows (using MinGW and MSYS), you need to alter the Makefile so that it generates windows/java friendly DLLs. Change the CFLAGS line to read:

CFLAGS=-shared -fpic -Wl,--add-stdcall-alias

Also change the output name, "NATIVE_SO", to be the windows name of the file the provided java code will look for:


Then navigate into the /wrapper/java folder in msys and execute:

$ make check

MinGW needs to be java enabled to complete this properly (I think) - you can do this most easily by simply running the install file for MinGW again and checking the box for java, if you didn't do so on original installation. You can also edit the fstab file to point /java to your Windows copy of java, though if you go this route you'll need to edit the Makefile to point to the appropriate include directories. Once you've generated the dll, copy it (from the /wrapper/java/native folder) to wherever in windows you're actually running the dmtx code from (i.e. netbeans project root directory) and viola! you now have access to the DMTXImage and DMTXTag classes.

3. Installing libdmtx-java on OS X

OS X is Darwin based, and doesn't use standard malloc.h. You need to change

#include <malloc.h>


#include <stdlib.h>

in native/org_libdmtx_DMTXImage.c

Also, the option for building a library is -dynlib, not -shared, and the include files are in a funny place, so the relevant lines in my makefile are now:

CFLAGS=-dynamiclib -fPIC
INCLUDE=-I ../.. \
    -I /System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers/

(This was on 10.5, Intel)

Also, it didn't like looking in LD_LIBRARY_PATH for the native libs, so to test it I ran:

java -Djava.library.path=native GUIExample ../../test/rotate_test/images/test_image07.png

(I believe the -D stye is more modern and portable)

4. Anything Else?

Is something missing from these instructions? If you spent hours searching for a solution that you feel should be included here then please update this page directly.

[Add your documentation here…]

I was trying to install the Java wrapper on Mac OSX 10.5 (Leopard). I followed all of the steps here, but still received a 'no dmtx in java.library.path' error. I happened to look at the Wikipedia page on shared objects and libraries, and it mentioned that OSX uses .so-style libraries with a .dylib extension. When I renamed a copy of to libdmtx.dylib, everything ran fine! —karajade

Since the splitting of the project (wrappers, libdmtx and dmtx-utils in differents projects), you must clone the git project of the wrapper in the directory of the source of libdmtx to not break the build —gholafox

I was trying to compil the Java wrapper on Mac OSX 10.6 (Snow Leopard) and I had an error like this:

ld: warning: in ../../libdmtx_la-dmtx.lo, file was built for unsupported file format which is not the architecture being linked (i386)

So, do not forget to add the arch when you call the configure script for libdmtx like this:

Laureline:libdmtx-0.7.4 gholafox$ ./configure CC="gcc -arch x86_64"

5. This Document

Updates to this page ultimate feed into the wrapper/java/README file that is distributed with the source package. If you are looking for information specific to an older release, please refer to this file as it exists in that package version.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License