Results 1 to 4 of 4

Thread: Using 3rd part static library with QT Creator in Win7

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2014
    Posts
    2
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Using 3rd part static library with QT Creator in Win7

    I am new to QT and i have encountered the problem for which i cant find the solution.. so i want to ask for Your advices

    So, currently i am writing the application for android with QT creator in win7. When it is simple (aka 'hello world') it compiles and runs on the connected android tablet successfully. The problem begins when i try to use 'libusb' library - qt creator shows lots of linking errors and fails to build (more details ahead).



    I have downloaded latest libusb-1.0.19.7z (from here) with .a and .h files. I have just copy/paste Header (libusb.h) and static lib (libusb-1.0.a) files (for MinGW32) to my project directory and added to project using qt creator.


    after adding library, .pro file is like this (skipping basic code lines)...
    Qt Code:
    1. ...
    2. unix:!macx: LIBS += -L$$PWD/ -lusb-1.0
    3.  
    4. INCLUDEPATH += $$PWD/
    5. DEPENDPATH += $$PWD/
    6.  
    7. unix:!macx: PRE_TARGETDEPS += $$PWD/libusb-1.0.a
    To copy to clipboard, switch view to plain text mode 


    When i try to build project, it shows this:

    Qt Code:
    1. 23:55:37: Running steps for project TestAndroid...
    2. 23:55:37: Configuration unchanged, skipping qmake step.
    3. 23:55:37: Starting: "C:\Qt\Tools\mingw482_32\bin\mingw32-make.exe"
    4. C:\Qt\5.3\android_armv7\bin\qmake.exe -spec android-g++ CONFIG+=debug CONFIG+=declarative_debug CONFIG+=qml_debug -o Makefile ..\TestAndroid\TestAndroid.pro
    5. C:\android\ndk\android-ndk-r10b/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ --sysroot=C:\android\ndk\android-ndk-r10b/platforms/android-9/arch-arm/ -Wl,-soname,libTestAndroid.so -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libTestAndroid.so main.obj testclassAndroid.obj hid.obj qrc_qml.obj moc_testclass.obj -LC:\android\ndk\android-ndk-r10b/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -LC:\android\ndk\android-ndk-r10b/platforms/android-9/arch-arm//usr/lib -LC:/Users/dainius/Desktop/qt/projects/TestAndroid/ -lusb-1.0 -LC:/Qt/5.3/android_armv7/lib -lQt5Quick -Lc:\Utils\android\ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -Lc:\Utils\android\ndk/platforms/android-9/arch-arm//usr/lib -LC:\Utils\icu32_51_1_mingw482\lib -LC:\utils\postgresql\pgsql\lib -LC:\utils\mysql\mysql\lib -LC:\Utils\pgsql\lib -LC:\temp\opensll-android-master\openssl-android-master\lib -LC:\Qt\5.3\android_armv7/lib -lQt5Qml -lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core -lGLESv2 -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
    6. ..\TestAndroid/libusb.h:1792: error: undefined reference to 'libusb_control_transfer'
    7. ..\TestAndroid/hid.c:484: error: undefined reference to 'libusb_get_bus_number'
    8. ..\TestAndroid/hid.c:485: error: undefined reference to 'libusb_get_device_address'
    9. ..\TestAndroid/hid.c:499: error: undefined reference to 'libusb_init'
    10. ..\TestAndroid/hid.c:514: error: undefined reference to 'libusb_exit'
    11.  
    12. and more undefined references...
    To copy to clipboard, switch view to plain text mode 


    btw, readme.txt file from libusb-1.0.19.7z tells this:
    Qt Code:
    1. MinGW/cygwin
    2. - Copy libusb.h, from include/libusb-1.0/ to your default include directory,
    3. and copy the MinGW32/ or MinGW64/ .a files to your default library directory.
    4. Or, if you don't want to use the default locations, make sure that you feed
    5. the relevant -I and -L options to the compiler.
    6. - Add the '-lusb-1.0' linker option when compiling.
    To copy to clipboard, switch view to plain text mode 



    So what i am doing wrong here or am i missing something??
    Thanks in advance.


    More info:
    I am using QT Creator 3.2.2, QT 5.3.2 (msvc 2010, 32bit). I have tried on WIN7 32bit and 64bit

  2. #2
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Using 3rd part static library with QT Creator in Win7

    I am using QT Creator 3.2.2, QT 5.3.2 (msvc 2010, 32bit)
    I don't think that you are using MSVC when compiling your C++ application to run on Android. Normally you use the appropriate compiler for your architecture which comes with the Android NDK to compile your C++ application as well as the libraries you need to use.

    I have just copy/paste Header (libusb.h) and static lib (libusb-1.0.a) files (for MinGW32) to my project directory and added to project using qt creator.
    You can not link against libraries compiled with MinGW (for AMD64/x86 Windows platform!). I would compile libusb from the source using the appropriate compiler from the Android NDK, see: https://github.com/libusb/libusb/tree/master/android

  3. The following user says thank you to Infinity for this useful post:

    daynen (13th November 2014)

  4. #3
    Join Date
    Nov 2014
    Posts
    2
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using 3rd part static library with QT Creator in Win7

    thanks for the answer.

    i used compiler from Android NDK and built 'libusb' for Android (i have downloaded the source files from the github). In result i got libs and obj folders with .so files in it.

    So, i updated my .pro file accordingly...


    Qt Code:
    1. unix:!macx: LIBS += -L$$PWD/../../libusb-master/android/libs/armeabi-v7a/ -lusb1.0
    2.  
    3. INCLUDEPATH += $$PWD/../../libusb-master/android/libs/armeabi-v7a
    4. DEPENDPATH += $$PWD/../../libusb-master/android/libs/armeabi-v7a
    To copy to clipboard, switch view to plain text mode 

    ...and it finally compiled successfully.

    Unfortunately, my program fails to start on Android tablet and QT creator shows the following:

    Qt Code:
    1. Starting remote process.
    2.  
    3. Unable to start "org.qtproject.example.HidManager".
    To copy to clipboard, switch view to plain text mode 

    Checked the logcat and found:

    Qt Code:
    1. E/dalvikvm(13795): dlopen("/data/app-lib/org.qtproject.example.HidManager-1/libH
    2. idManager.so") failed: Cannot load library: soinfo_link_image(linker.cpp:1635):
    3. could not load library "libusb1.0.so" needed by "libHidManager.so"; caused by lo
    4. ad_library(linker.cpp:745): library "libusb1.0.so" not found
    To copy to clipboard, switch view to plain text mode 


    What could be the suggestions what i am doing wrong here (again)?

    BTW, when removing the usage of libusb library from the project, application on android runs successfully.
    Last edited by daynen; 11th November 2014 at 13:20.

  5. #4
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Using 3rd part static library with QT Creator in Win7

    Since you're linking dynamically against libusb you need to deploy the library with your application. You can use ANDROID_EXTRA_LIBS to achieve that.
    Have a look at the documentation: http://qt-project.org/doc/qt-5/deployment-android.html

  6. The following user says thank you to Infinity for this useful post:

    daynen (13th November 2014)

Similar Threads

  1. Linking Static Library with Qt Creator
    By augusbas in forum Qt Tools
    Replies: 3
    Last Post: 12th September 2013, 07:08
  2. win7 x64 + mingw32 + static build failed
    By dkoryagin in forum Installation and Deployment
    Replies: 0
    Last Post: 8th August 2013, 09:46
  3. Replies: 1
    Last Post: 28th August 2011, 01:18
  4. Replies: 2
    Last Post: 19th February 2011, 12:26
  5. Replies: 1
    Last Post: 18th February 2011, 12:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.