This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] KDE4, CMake and a JNI library

Tags: None
(comma "," separated)
User avatar
La_MouettE
Registered Member
Posts
2
Karma
0
OS
Hi everyone,

I'm trying to write a small java native library in order to access to KDE4 systray from java. Since I'm not very experienced with C++, I first tried a very simple 'hello world library', without any KDE4 code in it. I have created also a CMakeLists.txt file to compile the library. With the following code, everything works fine :

Code: Select all
project (JKDE4)
cmake_minimum_required(VERSION 2.6)
find_package(JNI REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
add_library(JKDE4 SHARED kde4_KDE4Test.cpp)


Then I tried to include KDE4 headers into the CMakeLists.txt file (C++ sources not modified, still no KDE4 code), but java complains about an UnsatisfiedLink, because it couldn't find the function in the compiled library. Here's the CMakeLists.txt file with KDE4 headers :

Code: Select all
project (JKDE4)
cmake_minimum_required(VERSION 2.6)
find_package(JNI REQUIRED)
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
include_directories(${JNI_INCLUDE_DIRS})
kde4_add_library(JKDE4 SHARED kde4_KDE4Test.cpp)


When I run a 'nm -g' to see external symbols on the generated libraries, in the first case I indeed have the exported native java funcion :

Code: Select all
000006cc T Java_kde4_KDE4Test_test


but in the second case it doesn't appear anymore, althought it appears in the complete symbol list. I guess that's why java couldn't find it. Any idea on how to make it available ?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Can you please post the Full Sources? You will need to ensure the symbols needed have been exported. ( kde_export.h helps here )


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS
Since the new tray stuff is based on D-Bus, it is probably easier to do this native in Java using the Java D-Bus bindings.

The old and still standard way of system tray integration is most likely already implemented in the Java Class Library or JDIC http://javadesktop.org/articles/jdic/

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
User avatar
La_MouettE
Registered Member
Posts
2
Karma
0
OS
Thank you for your answers !

I managed to solve my problem by debugging cmake execution ; g++ switch -fvisibility=hidden is added when compiling a kde project, that's why I coudn't see the functions in the external symbols of the library. I added a gcc pragma instruction in the header JNI file, and the functions are now visible to java. Everything is explained here : http://gcc.gnu.org/wiki/Visibility

You're definitly right, there are implementations of system tray in java, but because of their portability, they lack some functions : for example, with JDIC transparency is not supported. I want a tight integration with the desktop, with notifications, etc. That's why I started with JNI.

The D-Bus stuff however sounds very interesting. I'll look into that.

Last edited by La_MouettE on Mon Mar 30, 2009 9:49 pm, edited 1 time in total.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell