[CMake] SWIG - Adding Java module on OSX

Nicholas Yue yue.nicholas at gmail.com
Sun Sep 14 08:27:22 EDT 2008


Hi,

    I am using the macro SWIG_ADD_MODULE.

        SWIG_ADD_MODULE ( ribclient java RIBClient.i ParameterList.cpp )

    The generated linker flag does not produce a loadable JNI module (it 
compiles and build but is not usable).

/usr/bin/c++   -bundle -headerpad_max_install_names  -o 
libribclient.jnilib CMakeFiles/ribclient.dir/RIBClientJAVA_wrap.cxx.o 
CMakeFiles/ribclient.dir/ParameterList.cpp.o 
-L/usr/local/cppunit/1.12.1/lib -L/Users/nicholas/temp/pkg/OpenEXR/lib 
-L/usr/local/ILMBase/1.0.1/lib 
-L/Applications/Graphics/3Delight-7.0.51/lib -L. ../libutils.a -l3delight

    I have found that the correct flag should be -dynamiclib instead of 
-bundle

    i.e.
/usr/bin/c++   -dynamiclib -headerpad_max_install_names  -o 
libribclient.jnilib CMakeFiles/ribclient.dir/RIBClientJAVA_wrap.cxx.o 
CMakeFiles/ribclient.dir/ParameterList.cpp.o 
-L/usr/local/cppunit/1.12.1/lib -L/Users/nicholas/temp/pkg/OpenEXR/lib 
-L/usr/local/ILMBase/1.0.1/lib 
-L/Applications/Graphics/3Delight-7.0.51/lib -L. ../libutils.a -l3delight

    I ended putting this in the CMakeLists.txt file to get the above 
desired outcome

    IF (APPLE)
        SET(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS "-dynamiclib 
-headerpad_max_install_names")
    ENDIF (APPLE)

    If this is indeed a bug, I hope the proper fix will make it's way 
into 2.6.2 as I see that an RC is in the works.

Regards



More information about the CMake mailing list