[zeromq-dev] Quick JZMQ howto on Windows

Steven McCoy steven.mccoy at miru.hk
Wed Oct 26 19:46:31 CEST 2011


1)  Build ZeroMQ or install a prepared package.  I built with SDK 7.1 but I
also have MSVC 2010 Express and Pro installed.

http://www.microsoft.com/download/en/details.aspx?id=8279

2)  Clone JZMQ from GitHub, might be easier with Cygwin.

$ *git clone https://github.com/zeromq/jzmq.git*

http://cygwin.com/install.html

3)  Insert attached CMakeLists.txt, you probably want to install *CMake *for
Windows too.

http://www.cmake.org/cmake/resources/software.html

4)  With a suitable JDK installed prepare the build:

http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-download-346242.html

c:\zeromq\jzmq\jzmq> *mkdir build64*

c:\zeromq\jzmq\jzmq> *cd build64*

c:\zeromq\jzmq\jzmq> *cmake .. -G "NMake Makefiles"*
-- The C compiler identification is MSVC
-- The CXX compiler identification is MSVC
-- Check for CL compiler version
-- Check for CL compiler version - 1600
-- Check if this is a free VC compiler
-- Check if this is a free VC compiler - no
-- Check for working C compiler: c:/Program Files (x86)/Microsoft Visual
Studio10.0/VC/bin/amd64/cl.exe
-- Check for working C compiler: c:/Program Files (x86)/Microsoft Visual
Studio10.0/VC/bin/amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: c:/Program Files (x86)/Microsoft Visual
Studio 10.0/VC/bin/amd64/cl.exe
-- Check for working CXX compiler: c:/Program Files (x86)/Microsoft Visual
Studio 10.0/VC/bin/amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Java version 1.6.0.27 configured successfully!
-- Found Java: C:/Program Files/Java/jdk1.6.0_27/bin/java.exe (found version
"1.6.0.27")
-- Found JNI: C:/Program Files/Java/jdk1.6.0_27/lib/jawt.lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/zeromq/jzmq/jzmq/build64

c:\zeromq\jzmq\jzmq> *cmake-gui .*

Change "*Debug*" to "*Release*", hit "*Configure*" and "*Generate*".

Java version 1.6.0.27 configured successfully!

 Configuring done

Generating done

5)  With NSIS installed you can jump to build the package or just build the
libraries.

http://nsis.sourceforge.net/Download

c:\zeromq\jzmq\jzmq> *nmake package*

or

c:\zeromq\jzmq\jzmq> *nmake*

Then output similar to as follows:


Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

[ 11%] Generating config.hpp
[ 22%] Generating org/zeromq/ZMQ.class, org/zeromq/ZMQ$$Context.class,
org/zeromq/ZMQ$$Socket.class, org/zeromq/ZMQ$$Poller.class,
org/zeromq/ZMQ$$Error.class, org/zeromq/ZMQException.class,
org/zeromq/ZMQQueue.class, org/zeromq/ZMQForwarder.class,
org/zeromq/ZMQStreamer.class, org/zeromq/EmbeddedLibraryTools.class, or
g/zeromq/App.class
[ 33%] Generating org_zeromq_ZMQ.h, org_zeromq_ZMQ_Error.h,
org_zeromq_ZMQ_Context.h, org_zeromq_ZMQ_Socket.h, org_zeromq_ZMQ_Poller.h
[ 44%] Generating lib/zmq.jar
Scanning dependencies of target jzmq
[ 44%] Generating org/zeromq/ZMQ.class, org/zeromq/ZMQ$$Context.class,
org/zeromq/ZMQ$$Socket.class, org/zeromq/ZMQ$$Poller.class,
org/zeromq/ZMQ$$Error.class, org/zeromq/ZMQException.class,
org/zeromq/ZMQQueue.class, org/zeromq/ZMQForwarder.class,
org/zeromq/ZMQStreamer.class, org/zeromq/EmbeddedLibraryTools.class, or
g/zeromq/App.class
[ 44%] Generating org_zeromq_ZMQ.h, org_zeromq_ZMQ_Error.h,
org_zeromq_ZMQ_Context.h, org_zeromq_ZMQ_Socket.h, org_zeromq_ZMQ_Poller.h
[ 55%] Building CXX object CMakeFiles/jzmq.dir/src/Context.cpp.obj
Context.cpp
[ 66%] Building CXX object CMakeFiles/jzmq.dir/src/Poller.cpp.obj
Poller.cpp
[ 77%] Building CXX object CMakeFiles/jzmq.dir/src/Socket.cpp.obj
Socket.cpp
C:\zeromq\jzmq\jzmq\src\Socket.cpp(176) : warning C4267: 'argument' :
conversion from 'size_t' to 'jsize', possible loss of data
C:\zeromq\jzmq\jzmq\src\Socket.cpp(182) : warning C4267: 'argument' :
conversion from 'size_t' to 'jsize', possible loss of data
C:\zeromq\jzmq\jzmq\src\Socket.cpp(476) : warning C4267: 'initializing' :
conversion from 'size_t' to 'int', possible loss of data
C:\zeromq\jzmq\jzmq\src\Socket.cpp(500) : warning C4267: 'initializing' :
conversion from 'size_t' to 'int', possible loss of data
[ 88%] Building CXX object CMakeFiles/jzmq.dir/src/util.cpp.obj
util.cpp
[100%] Building CXX object CMakeFiles/jzmq.dir/src/ZMQ.cpp.obj
ZMQ.cpp
Linking CXX shared library lib\jzmq.dll
   Creating library lib\jzmq.lib and object lib\jzmq.exp
[100%] Built target jzmq
Run CPack packaging tool...
CPack: Create package using NSIS
CPack: Install projects
CPack: - Run preinstall target for: JZMQ
CPack: - Install project: JZMQ
CPack: Create package
CPack: - package: C:/zeromq/jzmq/jzmq/build64/JZMQ-2.1.10-win64.exe
generated.


Then to test copy all the libraries into the perf directory from the
*jzmq *package
and build some examples.

C:\zeromq\jzmq\jzmq\perf>*"\Program Files\Java\jdk1.6.0_27"\bin\javac -cp
zmq.jar;. local_lat.java*

C:\zeromq\jzmq\jzmq\perf>*"\Program Files\Java\jdk1.6.0_27"\bin\javac -cp
zmq.jar;. remote_lat.java*

Then test:

C:\zeromq\jzmq\jzmq\perf>*"\Program Files\Java\jdk1.6.0_27\bin"\java
-Xcheck:jni -verbose:jni,class -classpath .;zmq.jar local_lat tcp://
127.0.0.1:5000 1 100*

C:\zeromq\jzmq\jzmq\perf>*"\Program Files\Java\jdk1.6.0_27"\bin\java
-classpath .;zmq.jar remote_lat tcp://127.0.0.1:5000 1 100*
message size: 1 [B]
roundtrip count: 100
mean latency: 85.0 [us]

The perf directory looks like this:

10/26/2011  01:18 PM    <DIR>          .
10/26/2011  01:18 PM    <DIR>          ..
10/26/2011  01:09 PM            16,384 jzmq.dll
10/03/2011  12:47 PM           445,952 libzmq.dll
10/26/2011  12:53 PM             1,492 local_lat.class
10/05/2011  05:07 PM             1,723 local_lat.java
10/05/2011  05:07 PM                68 local_lat.sh
10/05/2011  05:07 PM             2,278 local_thr.java
10/05/2011  05:07 PM                68 local_thr.sh
10/05/2011  05:07 PM               512 Makefile.am
10/05/2011  05:07 PM             9,988 Makefile.in
10/26/2011  01:18 PM             1,853 remote_lat.class
10/05/2011  05:07 PM             2,049 remote_lat.java
10/05/2011  05:07 PM                69 remote_lat.sh
10/05/2011  05:07 PM             1,722 remote_thr.java
10/05/2011  05:07 PM                69 remote_thr.sh
10/26/2011  01:09 PM            15,350 zmq.jar
              15 File(s)        499,577 bytes

Example packages to download:

http://miru.hk/archive/ZeroMQ-2.1.10-win64.exe
http://miru.hk/archive/JZMQ-2.1.10-win64.exe

Win32 didn't build as I think the installed JDK is 64-bit only.

-- 
Steve-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111026/a70c965c/attachment.htm>
-------------- next part --------------
# CMake build script for ØMQ Java bindings on Windows

cmake_minimum_required (VERSION 2.8)

project (JZMQ)
find_package (Java REQUIRED)
find_package (JNI REQUIRED)

find_program (JNI_JAVAH
	NAMES javah
	HINTS ${_JAVA_HINTS}
	PATHS ${_JAVA_PATHS}
)

#-----------------------------------------------------------------------------
# force off-tree build

if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "CMake generation is not allowed within the source directory!
Remove the CMakeCache.txt file and try again from another folder, e.g.:

   del CMakeCache.txt
   mkdir build
   cd build
   cmake ..
")
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})

#-----------------------------------------------------------------------------
# default to Release build

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release CACHE STRING
      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
      FORCE)
endif(NOT CMAKE_BUILD_TYPE)

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH  ${CMAKE_BINARY_DIR}/lib)

#-----------------------------------------------------------------------------
# platform specifics

add_definitions(
        -DWIN32
	-DDLL_EXPORT
	-DFD_SETSIZE=1024
)

#-----------------------------------------------------------------------------
# source files

set(java-sources
	org/zeromq/ZMQ.java
	org/zeromq/ZMQException.java
	org/zeromq/ZMQForwarder.java
	org/zeromq/ZMQQueue.java
	org/zeromq/ZMQStreamer.java
	org/zeromq/EmbeddedLibraryTools.java
	org/zeromq/App.java
)
set(java-classes
	org/zeromq/ZMQ.class
	org/zeromq/ZMQ$$Context.class
	org/zeromq/ZMQ$$Socket.class
	org/zeromq/ZMQ$$Poller.class
	org/zeromq/ZMQ$$Error.class
	org/zeromq/ZMQException.class
	org/zeromq/ZMQQueue.class
	org/zeromq/ZMQForwarder.class
	org/zeromq/ZMQStreamer.class
	org/zeromq/EmbeddedLibraryTools.class
	org/zeromq/App.class
)
set(javah-headers
	org_zeromq_ZMQ.h
	org_zeromq_ZMQ_Error.h
	org_zeromq_ZMQ_Context.h
	org_zeromq_ZMQ_Socket.h
	org_zeromq_ZMQ_Poller.h
)
set(cxx-sources
	Context.cpp
	Poller.cpp
	Socket.cpp
	util.cpp
	ZMQ.cpp
)

include_directories(
        src
	${CMAKE_CURRENT_BINARY_DIR}
)

#-----------------------------------------------------------------------------
# optional modules

add_definitions(
	-DZMQ_HAVE_OPENPGM
)
include_directories(
	/zeromq/zeromq-2.1.10/include
	${JNI_INCLUDE_DIRS}
)
link_directories(
#	/zeromq/zeromq-2.1.10/build/lib
	/zeromq/zeromq-2.1.10/build64/lib
)

#-----------------------------------------------------------------------------
# source generators

foreach (source ${cxx-sources})
	list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
endforeach()

add_custom_command(
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/config.hpp
	COMMAND ${CMAKE_COMMAND}
	ARGS	-E
		copy
		${CMAKE_CURRENT_SOURCE_DIR}/builds/msvc/config.hpp
		${CMAKE_CURRENT_BINARY_DIR}/config.hpp
	DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/builds/msvc/config.hpp
)
list(APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/config.hpp)

add_custom_command(
	OUTPUT ${javah-headers}
	COMMAND ${JNI_JAVAH}
	ARGS	-jni
		-classpath ${CMAKE_CURRENT_BINARY_DIR}
		org.zeromq.ZMQ
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	DEPENDS ${java-classes}
)
list(APPEND sources ${javah-headers})

set (source-tmp "")
foreach (source ${java-sources})
	list (APPEND source-tmp ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
endforeach()
set (java-sources ${source-tmp})

add_custom_command(
	OUTPUT ${java-classes}
	COMMAND ${JAVA_COMPILE}
	ARGS	-classpath ${CMAKE_CURRENT_BINARY_DIR}
		-sourcepath ${CMAKE_CURRENT_SOURCE_DIR}/src
		-d ${CMAKE_CURRENT_BINARY_DIR}
		${java-sources}
	DEPENDS ${java-sources}
)

add_custom_command(
	OUTPUT lib/zmq.jar
	COMMAND ${JAVA_ARCHIVE}
	ARGS	cf
		lib/zmq.jar
		${java-classes}
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	DEPENDS ${java-classes}
)
list(APPEND sources lib/zmq.jar)

#-----------------------------------------------------------------------------
# output

add_library(jzmq SHARED ${sources})
target_link_libraries(jzmq libzmq.lib)

set(docs
        AUTHORS
	COPYING
	COPYING.LESSER
	ChangeLog
	INSTALL
	NEWS
	README
	README-PERF
)

install (TARGETS jzmq DESTINATION lib)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/lib/zmq.jar DESTINATION lib)
install (FILES ${docs} DESTINATION doc)

include (InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_VENDOR "Miru Limited")
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set (CPACK_PACKAGE_VERSION_MAJOR "2")
set (CPACK_PACKAGE_VERSION_MINOR "1")
set (CPACK_PACKAGE_VERSION_PATCH "10")
include (CPack)

# end of file


More information about the zeromq-dev mailing list