<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
On 08/06/2009 06:49 AM, Mathieu Malaterre wrote:
<blockquote
cite="mid:bf0c3b3f0908060549k48569c5fv38313bffd60e019f@mail.gmail.com"
type="cite">
<pre wrap="">On Thu, Aug 6, 2009 at 2:46 PM, Mathieu
Malaterre<a class="moz-txt-link-rfc2396E" href="mailto:mathieu.malaterre@gmail.com"><mathieu.malaterre@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Thu, Aug 6, 2009 at 2:27 PM, Stephen Roderick<a class="moz-txt-link-rfc2396E" href="mailto:kiwi.net@mac.com"><kiwi.net@mac.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Aug 6, 2009, at 06:02 , Mathieu Malaterre wrote:
</pre>
<blockquote type="cite">
<pre wrap="">On Wed, Aug 5, 2009 at 6:55 PM, Stephen Roderick<a class="moz-txt-link-rfc2396E" href="mailto:kiwi.net@mac.com"><kiwi.net@mac.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">The existing UseSWIG.cmake file creates a MODULE and not a SHARED
library.
The module is unuseable by any program trying to load dynamic libraries
(eg
wrapped Java). The attached patch fixes this problem for our situations.
Demonstrated on both Mac OS X Leopard and Ubuntu Jaunty.
Is this a known issue? I searched what I could of the list and the 'net,
and
couldn't find anything on this.
</pre>
</blockquote>
<pre wrap="">No, you are confusing the C++ library and the Java binding. Instead:
ADD_LIBRARY(foo SHARED ${foo_SRCS}) # the actual shared lib
SWIG_ADD_MODULE(foojni java foo.i)
SWIG_LINK_LIBRARIES(foojni foo
${JNI_LIBRARIES}
)
The next time you will want to create -say- a python module you'll
simply link to your *shared C++* library:
SWIG_ADD_MODULE(foopython python foo.i)
SWIG_LINK_LIBRARIES(foopython foo
${PYTHON_LIBRARIES}
)
</pre>
</blockquote>
<pre wrap="">Unfortunately, that is what we currently have.
<code>
ADD_LIBRARY(MyInterfaceCpp ...)
Find_Package(SWIG REQUIRED)
Find_Package(JNI REQUIRED)
INCLUDE(UseSWIG)
INCLUDE_DIRECTORIES(${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
SET_SOURCE_FILES_PROPERTIES(MyInterface.i PROPERTIES CPLUSPLUS 1)
# compile swig with package flag
SET(CMAKE_SWIG_FLAGS -package x.y.z)
SWIG_ADD_MODULE(MyInterface java MyInterface.i)
SWIG_LINK_LIBRARIES(MyInterface
MyInterfaceCpp ...)
</code>
The failure comes when you try to load the SWIG-output, JNI library from
within java, using something like
<code>
static {
System.loadLibrary("MyInterface");
}
</code>
With a module in a "MyInterface.so" file (what SWIG currently outputs), the
</pre>
</blockquote>
<pre wrap="">No. On Linux 'lib' is always preprended, even for MODULE. I am not
sure about MacOSX.
</pre>
<blockquote type="cite">
<pre wrap="">above call fails on both Mac OS X and Linux. They both need a correctly
named dynamic library, hence the patch.
</pre>
</blockquote>
<pre wrap="">I have been using this in gdcm and it works fine on Linux:
<a class="moz-txt-link-freetext" href="http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Wrapping/Java/gdcm.i?r1=5779&r2=5799">http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Wrapping/Java/gdcm.i?r1=5779&r2=5799</a>
</pre>
</blockquote>
<pre wrap=""><!---->
My bad... I forgot that SWIG stuff always override the 'lib' setting,
hence you have to revert it:
<a class="moz-txt-link-freetext" href="http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Wrapping/Java/CMakeLists.txt?view=markup">http://gdcm.svn.sf.net/viewvc/gdcm/trunk/Wrapping/Java/CMakeLists.txt?view=markup</a>
See comments:
...
IF(UNIX)
SET_TARGET_PROPERTIES(${SWIG_MODULE_gdcmjni_REAL_NAME} PROPERTIES
PREFIX "lib")
ENDIF(UNIX)
...
I think this comes from the SWIG module initially designed based on
the python requirement where '_' would be preprended before the actual
lib name.
Sorry for the confusion.
</pre>
</blockquote>
<br>
And for python on Windows, I've had to do<br>
set_target_properties(... PROPERTIES SUFFIX ".pyd")<br>
or the module doesn't work with some versions of python.<br>
<br>
Clint<br>
<br>
</body>
</html>