Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Mac OSX QT-Creator Static Library *.a (clang-Compiler) in Eclipse CDT (JNI) *.jnilib (cpp-Compiler) einbinden (Download Projekte)

Mac OSX QT-Creator Static Library *.a (clang-Compiler) in Eclipse CDT (JNI) *.jnilib (cpp-Compiler) einbinden (Download Projekte)

Scheduled Pinned Locked Moved German
staticeclipsecdtjniclangcppjnilibmac os xstatic libraryeclipse cdtjava jnillvm
1 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moozoom
    wrote on 17 Jun 2015, 08:36 last edited by moozoom
    #1

    Hallo liebe QT-Community,

    ich arbeite mich gerade in QT ein und finde die QT-Creator-Entwicklungsumgebung sehr gut.
    Ich habe eine Static Library (*.a) erstellt, die ich in einem anderen Projekt wiederverwenden möchte.
    Dieses kleine QT-Projekt findet Ihr u.a. in dem *.ZIP-Archiv.

    Download: http://moozoom.de/share/QT_vs_Java_JNI_over_CDT.zip

    In der *.pro habe ich folgende Build-Informationen angegeben:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2015-06-13T16:02:21
    #
    #-------------------------------------------------

    QT -= gui

    TARGET = QTStaticLibrary
    TEMPLATE = lib
    CONFIG += staticlib

    @CONFIG += MAC_CONFIG
    MAC_CONFIG {
    QMAKE_CXXFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.10
    QMAKE_LFLAGS = -std=c++11 -stdlib=libstdc++ -mmacosx-version-min=10.10
    }

    QMAKE_CFLAGS_RELEASE = -Os -momit-leaf-frame-pointer

    SOURCES += qtstaticlibrary.cpp

    HEADERS += qtstaticlibrary.h
    unix {
    target.path = /usr/lib
    INSTALLS += target
    }

    Die Entwicklung erfolgt auf einem Mac OS X 10.10 und ich habe die Static Library (.a) für eine Desktop-Anwendung erstellen. Kompiliert wird die Static Library (.a) mit dem clang (LLVM)-Compiler.
    Da ich aufgrund einer speziellen Laufzeitumgebung – basierend auf JAVA – Eclipse LUNA CDT als Haupt-Entwicklungsumgebung nutzen werde, möchte ich diese Static Library (*.a) in dieses CDT-Projekt einbinden und über JNI in JAVA nutzen. Allerdings nutze ich für meinen CDT-Build den cpp-Compiler.

    Tutorial JNI:
    https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html

    Libraries in Eclipse CDT einbinden:
    http://stackoverflow.com/questions/8332460/how-do-i-include-a-statically-linked-library-in-my-eclipse-c-project

    Das Makefile für mein HelloJNI-Projekt ist folgendermaßen aufgebaut:

    # Define a variable for classpath
    CLASS_PATH = ../bin

    # Define a virtual path for .class in the bin directory
    vpath %.class $(CLASS_PATH)

    # Modify the "makefile" as follows to generate the shared library "libHello.jnilib" for Mac.

    all : libHello.jnilib

    # $@ matches the target, $< matches the first dependancy
    # The -lstdc++ flag tells the linker to include the C++ Standard Library
    libHello.jnilib : HelloQT2JNI.o
    g++ -lstdc++ -v -Wl -shared -o $@ $< libQTStaticLibrary.a

    # $@ matches the target, $< matches the first dependancy
    # -c flag to tell the compiler to skip the link stage: "ld: symbol(s) not found for architecture x86_64"
    HelloQT2JNI.o : HelloQT2JNI.cpp HelloQT2JNI.h
    gcc -I"/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/include" -I"/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/include/darwin" -c $< -o $@

    # $* matches the target filename without the extension
    HelloQT2JNI.h : HelloQT2JNI.class
    javah -classpath $(CLASS_PATH) $*

    clean :
    rm HelloQT2JNI.h HelloQT2JNI.o libHello.jnilib

    Ich rufe die Funktion hello() in meiner QT Static Library folgendermaßen auf:

    #include <jni.h>
    #include <iostream>
    #include "HelloQT2JNI.h"

    #include "qtstaticlibrary.h"

    using namespace std;

    JNIEXPORT void JNICALL Java_HelloQT2JNI_sayHello__(JNIEnv *, jobject)
    {
    cout << "Hello World!" << endl;

    QTStaticLibrary hello = QTStaticLibrary();
    hello.hello();

    return;
    }

    Irgendwie muss es doch möglich sein, die Static Library (.a) (clang-kompiliert) in meine Shared Library (.jnilib) (cpp-kompiliert) zu linken, sodass meine QT-Funktion auch über meine JNI-Wrapper-Library in JAVA aufgerufen werden kann.

    Ich erhalte über meine CDT Build Console folgende Fehlermeldung:

    make all
    javah -classpath ../bin HelloQT2JNI
    g++ -lstdc++ -v -Wl -shared -o libHello.jnilib HelloQT2JNI.o libQTStaticLibrary.a
    Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
    Target: x86_64-apple-darwin14.3.0
    Thread model: posix
    "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -o libHello.jnilib -lc++ HelloQT2JNI.o libQTStaticLibrary.a -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/lib/darwin/libclang_rt.osx.a
    Undefined symbols for architecture x86_64:
    "std::basic_ios<char, std::char_traits<char> >::widen(char) const", referenced from:
    QTStaticLibrary::hello() const in libQTStaticLibrary.a(qtstaticlibrary.o)
    "std::ostream::put(char)", referenced from:
    QTStaticLibrary::hello() const in libQTStaticLibrary.a(qtstaticlibrary.o)
    "std::ostream::flush()", referenced from:
    QTStaticLibrary::hello() const in libQTStaticLibrary.a(qtstaticlibrary.o)
    "std::ios_base::Init::Init()", referenced from:
    __GLOBAL__sub_I_qtstaticlibrary.cpp in libQTStaticLibrary.a(qtstaticlibrary.o)
    "std::ios_base::Init::~Init()", referenced from:
    __GLOBAL__sub_I_qtstaticlibrary.cpp in libQTStaticLibrary.a(qtstaticlibrary.o)
    "std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)", referenced from:
    QTStaticLibrary::hello() const in libQTStaticLibrary.a(qtstaticlibrary.o)
    "std::cout", referenced from:
    QTStaticLibrary::hello() const in libQTStaticLibrary.a(qtstaticlibrary.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [libHello.jnilib] Error 1

    Das QT-Demo-Projekt und das Eclipse LUNA CDT-Demo-Projekt könnt Ihr als *.ZIP-Archiv herunterladen. Aktuell ist das JNI-Demo-Projekt lauffähig, wenn der QT-Aufruf auskommentiert wird. Die qt-Files findet Ihr im Unterordner „jni/<qtstaticlibrary.h, libQTStaticLibrary.a>“.

    Download: http://moozoom.de/share/QT_vs_Java_JNI_over_CDT.zip

    Zusammenfassung:
    Ich möchte eine Static Library (*.a), die ich mit dem QT-Creator unter Mac OS X 10.10 erstellt habe in mein Eclipse LUNA CDT-Projekt einbinden, so dass ich meine QT-Funktionen über Java JNI in meiner Java-Anwendung nutzen kann. Ich möchte mit dem QT-Creator arbeiten, um die Static Libraries zu entwickeln und mit Eclipse LUNA CDT, um meine Haupt-Anwendung, die auf der speziellen JAVA-basierten Laufzeitumgebung basiert, zu entwickeln.

    Vielen Dank im Voraus für Eure Hilfe :-)

    1 Reply Last reply
    0

    1/1

    17 Jun 2015, 08:36

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved