ANT+ integration in my QT project



  • Hi guys,

    I posted a few time here, I'm building an free indoor training software
    "Here is a prototype":https://www.dropbox.com/s/3x8ujf2j2kmq6b7/prototype.png

    My application need to integrate ANT+ sensors (sensor that records various statistic coming from the bike) in real time. I have found some C++ source code that is supplied from ANT+ doing just that "here":http://www.thisisant.com/developer/resources/downloads

    My problem : the code supplied is made with Visual studio and use "ANT_LIB.vcproj" file for the project, I would like to integrate all the source code in QT creator and convert this project to a .pro or .pri. The source code supplied is pure C++ (.cpp, .h, .hpp) The source code for Windows and Mac supplied look the same, (mac not having the .vcproj file)
    Here is some screenshot of the project structure :
    "#1":https://www.dropbox.com/s/gkhbnfl4s48f865/ant1.png
    "#2":https://www.dropbox.com/s/h0alsdthjxyqwa7/ant2.1.png
    "#3":https://www.dropbox.com/s/6pvvhcz4gxssu23/ant2.2.png

    So Is it possible to integrate a pure C++ project in QtCreator ? I'm looking for a good way to merge this code with my existing project (one .pro project with multiple small .pri project)

    Thanks!



  • if you want to build on top other sources I think there is no other way than, as you pointed out, to add them to your pro/pri files, and integrate in your application, if their design allows it, and where not possible you have to do working copies into your app src tree to adapt before integration ...

    to be honest I have not seen other magical way to build on top other project's source ...



  • Thanks Nicu I will try to integrate it if it's possible



  • Hey Nicu,

    I have tried to convert the entire project to a .pro
    Creating a .pri file for each folder of the project.
    You can see what it looks like "here":https://www.dropbox.com/s/010fc3ykr9byuvu/errorConvert.png

    I think I'm at the point of giving up and trying Visual studio..
    There's a lot of conversion error as you can see
    example :
    C:\QT\Qtworkspace\ANT_LIB\software\serial\WinDevice.cpp:390: error: C2664: 'LoadLibraryW' : cannot convert parameter 1 from 'char [255]' to 'LPCWSTR'

    So my next step is to try and build it with visual studio express, see if it's less work! then maybe use this "tool":http://blog.codeimproved.net/2010/12/qt-creator-sln-files-and-pro-files/

    thank you



  • Hi,

    have you seen these in your link?

    bq. Do expect to make minor adjustments to the generated files, as the conversion is not perfect.
    Note: This doesn’t work with the VS Express edition, since that version doesn’t support plugins.

    better to understand what headers are included in VS solutions by checking the source files and project configuration than giving up :) ... tbh I would rather integrate by QtCreator than mixing with VS proj files whether it might work for some cases or not ....

    till conversions in your integration take care not having any undeclared identifier yielding some headers still missing



  • I just download Visual Studio Express 2013 and it compiled on first try.

    Yeah I saw that, so either I have to modify the source code to integrate it in Qtcreator, or maybe compile it in VisualStudio and then use the compiled version in Qtcreator?

    I'm not sure I understand the conversion error in QTCreator, I use the same compiler (MSVC2010)? From what I read the problem is related to encoding..
    So far I still have 18 error left, not that bad, all related to conversion:
    C2664: 'SNPRINTF' : cannot convert parameter 1 from 'TCHAR *' to 'char *'



  • just an idea: hit F2 over TCHAR to check how it is defined (by typedef) ... I guess it would be WCHAR because VS projects are configured for Unicode; try without Unicode Character Set



  • Yes you were right, it is defined by WCHAR:

    You suggest changing all WCHAR to CHAR? there's no way of using Unicode in QTCreator? Thanks for the help :)

    @#ifndef _TCHAR_DEFINED
    typedef WCHAR TCHAR, *PTCHAR;
    typedef WCHAR TBYTE , PTBYTE ;
    #define _TCHAR_DEFINED
    #endif /
    !_TCHAR_DEFINED */@



  • try to add in pro file

    @DEFINES -= UNICODE@

    and check if TCHAR is typedefed as char



  • This line fixed all the conversion error, fantastic!
    TCHAR is now defined as char

    Now I got one last error :
    --WinDevice.obj:-1: error: LNK2019: unresolved external symbol __imp__CharNextA@4 referenced in function "struct IdEntry __cdecl GetIdType(char const *)" (?GetIdType@@YA?AUIdEntry@@PBD@Z)
    --WinDevice.obj:-1: error: LNK2019: unresolved external symbol imp__RegQueryValueExA@24 referenced in function "char * * cdecl GetRegMultiSz(struct HKEY *,char const *)" (?GetRegMultiSz@@YAPAPADPAUHKEY@@PBD@Z)

    Here is the project structure I'm trying to import (only imported ANT_LIB so far). The method I used to import the project was to create a new Plain C++ Project (Not CMAKE build), copy all the file from the ANT_LIB original project to my new project, make 1 .pri file for each subfolder, add all the header and source file in the .pri file.

    Note : ANT_LIB has no executable, the exe is in DEMO_LIB which is not yet imported in QtCreator (shouldn't cause problem because the project is lower in the tree)

    Project hierarchy :

    @ ANT_LIB
    |
    |
    |
    ---------------------------
    | |
    | |
    | |
    ANT_DLL (C++) DEMO_LIB (C++)
    |
    |
    |
    DEMO_DLL (C++) @



  • bq. the exe is in DEMO_LIB which is not yet imported in QtCreator

    I guess demo_lib is a demo exe using ANT_DLL at runtime, like you try to do, no need of it ... you cannot import such exe in QtCreator

    you only need the export library ANT_LIB to link statically to dll functions(in bin will be added code for loading the right library, pointers to functions with right signature and for getting the function addressees from loaded dll at runtime) and other required libs: I think you miss user32.lib !?



  • Hey, Demo_LIB is just a project containing Demo.cpp and Demo.h, it is a command line application that use ANT_LIB

    I am a complete newbie to QtCreator and C++... I will try to find how to export the library ANT_LIB.

    I haven't found user32.lib in the project?
    Here is the source code for ANT+ if you want to take a look:
    http://www.thisisant.com/resources/ant-windows-library-package-with-source-code/

    Thanks again for your time, I should hire you so you can come teach me all the basics !



  • first, you need to compile the whole ANT_Windows_Library_Package_v3.2, then in ANT_Windows_Library_Package_v3.2/Debug you'll find the dll(ANT_DLL.dll) its export library ANT_DLL.lib and the static library ANT_Lib.lib for static building(no dll used)

    DEMO_DLL uses ANT_DLL.dll and ANT_DLL.lib which is just an export library for dll and other few .lib files (see Additional Dependencies in VS project Linker->Input)

    DEMO_LIB uses ANT_Lib.lib which is a static library(all static code will be in DEMO_LIB.exe) and check how big is its size compared to ANT_DLL.lib



  • Oh i'm starting to understand.

    I have compiled the whole project "ANT_Windows_Library_Package_v3.2", In the debug folder, I have the lib you mentioned. Now let's say I want to use "ANT_LIB.lib" in a Demo project I just created, how do you actually use the "ANT_LIB.lib" in another project? I have tried the below project; Demo Project.pro, that is actually the project DEMO_LIB that I imported in QtCreator),
    Thanks very much, tell me you paypal account for your payment :)

    So what is the difference between using a static lib or a dll? I will probably use the static lib since it seems easier for me (I don't mind the bigger size)

    Demo Project.pro
    @------------------------------

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    #DEFINES -= UNICODE

    #No longer used (use static library ANT_Lib.lib compiled with VisualStudio Express)
    #include (inc/inc.pri)
    #include (libraries/libraries.pri)
    #include (common/common.pri)
    #include (software/ANTFS/ANTFS.pri)
    #include (software/serial/serial.pri)
    #include (software/serial/device_management/device_management.pri)
    #include (software/system/system.pri)
    #include (software/USB/USB.pri)
    #include (software/USB/device_handles/device_handles.pri)
    #include (software/USB/devices/devices.pri)

    SOURCES += demo.cpp

    HEADERS += demo.h

    LIBS += -LC:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\Debug
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\Debug

    @

    "C:\QT\Qtworkspace\ANT_LIB\demo.h:13: error: C1083: Cannot open include file: 'types.h': No such file or directory"



  • I linked the static library ANT_LIB.lib in my pro file

    New Demo_lib.pro :

    @TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    SOURCES += demo.cpp

    HEADERS += demo.h

    #LIBS += -LC:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\Debug\lib
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\inc
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\serial
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\system
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB\devices
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB\device_handles
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB

    win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug/lib/ -lANT_LIB
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug/lib/ -lANT_LIBd
    else:unix: LIBS += -L$$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug/lib/ -lANT_LIB

    INCLUDEPATH += $$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug
    DEPENDPATH += $$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug

    win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug/lib/ANT_LIB.lib
    else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug/lib/ANT_LIBd.lib
    else:unix: PRE_TARGETDEPS += $$PWD/../../../Users/Toto/Desktop/ANT_Windows_Library_Package_v3.2/Debug/lib/libANT_LIB.a@

    Now I have error like :
    ANT_LIB.lib(dsi_serial_generic.obj):-1: error: LNK2038: mismatch detected for '_MSC_VER': value '1800' doesn't match value '1600' in demo.obj
    This seems to be because the static lib was compiled with VStudio express 2013, not the same compiler that QtCreator use
    "Reference":http://stackoverflow.com/questions/16703401/visual-studio-2010-mismatch-detected-msc-ver-value-doesnt-match



  • I did compile ANT_LIB successfully with QTCreator using this setup :

    ANT_LIB.pro
    @---------------

    QT -= gui

    TARGET = ANT_LIB
    TEMPLATE = lib

    CONFIG += staticlib

    DEFINES -= UNICODE

    include (inc/inc.pri)
    include (libraries/libraries.pri)
    include (common/common.pri)
    include (software/ANTFS/ANTFS.pri)
    include (software/serial/serial.pri)
    include (software/serial/device_management/device_management.pri)
    include (software/system/system.pri)
    include (software/USB/USB.pri)
    include (software/USB/device_handles/device_handles.pri)
    include (software/USB/devices/devices.pri)
    @

    When I try to run DEMO_LIB, I now get this error message :
    ANT_LIB.lib(WinDevice.obj):-1: error: LNK2019: unresolved external symbol __imp__CharNextA@4 referenced in function "struct IdEntry __cdecl GetIdType(char const *)" (?GetIdType@@YA?AUIdEntry@@PBD@Z)

    Almost there! I learned a lot today, sorry for the spam, just keeping a log for myself/maybe to help others



  • ANT_LIB.lib may compile but this does not necessarily mean that was linked correct to all required dependent libs: I mean this might be discovered later when other project is compiled against it and does calls to lib functions calling farther other functions from other libs .... is recommended to understand into which libs the unreferenced functions reside and take care the all libs where added in LIBS while compiling ANT_LIB



  • Thanks Nicu, I am on my way to debugging this error

    _ANT_LIB.lib(WinDevice.obj):-1: error: LNK2019: unresolved external symbol ___imp__CharNextA@4 referenced in function "struct IdEntry cdecl GetIdType(char const *)" (?GetIdType@@YA?AUIdEntry@@PBD@Z)

    Function GetIdType :

    @IdEntry GetIdType(LPCTSTR Id)
    {
    IdEntry Entry;

    Entry.InstanceId = FALSE;
    Entry.Wild = NULL;
    Entry.String = Id;
    
    if(Entry.String[0] == INSTANCEID_PREFIX_CHAR)
    

    {
    Entry.InstanceId = TRUE;
    Entry.String = CharNext(Entry.String); //-- Function causing the error!
    }
    if(Entry.String[0] == QUOTE_PREFIX_CHAR)
    {
    Entry.String = CharNext(Entry.String);
    }
    else
    {
    Entry.Wild = _tcschr(Entry.String,WILD_CHAR);
    }
    return Entry;
    }@

    Define CharNext:

    @WINUSERAPI
    LPSTR
    WINAPI
    CharNextA(
    __in LPCSTR lpsz);
    WINUSERAPI
    LPWSTR
    WINAPI
    CharNextW(
    __in LPCWSTR lpsz);
    #ifdef UNICODE
    #define CharNext CharNextW
    #else
    #define CharNext CharNextA
    #endif // !UNICODE@

    Error seems to be related to User32.dll, haven't found where to put this file yet...
    Thanks



  • as I told you, you need in LIBS also user32.lib, no need to take care where is User32.dll : as other sys dlls it is in Windows system directory (i.e. C:\Windows\system32 on XP) which is one of the searched path for a required dll



  • I added User32.lib in the .pro of DEMO_LIB project (if I add it to ANT_LIB, DEMO_LIB would not build, possible to bundle a lib inside a static lib?)

    How can I find all the lib dependency of project ANT_LIB? I have checked inside the visual studio project file, and couldn't find anything related to User32.lib

    I now get a new error :
    ANT_LIB.lib(WinDevice.obj):-1: error: LNK2019: unresolved external symbol imp__RegQueryValueExA@24 referenced in function "char * * cdecl GetRegMultiSz(struct HKEY *,char const *)" (?GetRegMultiSz@@YAPAPADPAUHKEY@@PBD@Z)

    line of code in cause :
    @while(RegQueryValueEx(hKey,Val,NULL,&dataType,(PBYTE)buffer,&reqSize) != NO_ERROR) {...}@

    Define RegQueryValueEx :
    @WINADVAPI
    LSTATUS
    APIENTRY
    RegQueryValueExA (
    __in HKEY hKey,
    __in_opt LPCSTR lpValueName,
    __reserved LPDWORD lpReserved,
    __out_opt LPDWORD lpType,
    __out_bcount_part_opt(*lpcbData, *lpcbData) __out_data_source(REGISTRY) LPBYTE lpData,
    __inout_opt LPDWORD lpcbData
    );
    WINADVAPI
    LSTATUS
    APIENTRY
    RegQueryValueExW (
    __in HKEY hKey,
    __in_opt LPCWSTR lpValueName,
    __reserved LPDWORD lpReserved,
    __out_opt LPDWORD lpType,
    __out_bcount_part_opt(*lpcbData, *lpcbData) __out_data_source(REGISTRY) LPBYTE lpData,
    __inout_opt LPDWORD lpcbData
    );
    #ifdef UNICODE
    #define RegQueryValueEx RegQueryValueExW
    #else
    #define RegQueryValueEx RegQueryValueExA
    #endif // !UNICODE@

    DEMO_LIB.pro
    @TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    SOURCES += demo.cpp

    HEADERS += demo.h

    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\inc
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\serial
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\system
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB\devices
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB\device_handles
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB

    LIBS += "C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\Debug\lib\ANT_LIB.lib"
    LIBS += "C:\Users\Toto\Desktop\LIBWIN\winv6.3_um_x86\User32.Lib"
    @



  • @LIBS+=C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\Debug\lib\ANT_LIB.lib
    User32.Lib@

    "RegQueryValueEx function":http://msdn.microsoft.com/en-us/library/windows/desktop/ms724911(v=vs.85).aspx

    you need Advapi32.lib

    this the comand line for linker in DEMO_LIB:

    /OUT:"D:\Coolstream\Qt\Studiu\ANT\ANT_Windows_Library_Package_v3.2\Debug\DEMO_LIB.exe" /INCREMENTAL /NOLOGO /LIBPATH:"D:\Coolstream\Qt\Studiu\ANT\ANT_Windows_Library_Package_v3.2\Debug" "ANT_LIB.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "D:\Coolstream\Qt\Studiu\ANT\ANT_Windows_Library_Package_v3.2\Debug\ANT_Lib.lib" /MANIFEST /ManifestFile:"Debug\DEMO_LIB.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\Coolstream\Qt\Studiu\ANT\ANT_Windows_Library_Package_v3.2\Debug\DEMO_LIB.pdb" /SUBSYSTEM:CONSOLE /PGD:"D:\Coolstream\Qt\Studiu\ANT\ANT_Windows_Library_Package_v3.2\Debug\DEMO_LIB.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

    see in LIBPATH how many .lib it seems needed



  • Thanks Nicu, finally the demo is working!!
    I used Dependecy Walker and found that DEMO_LIB.exe uses KERNEL32.DLL, USER32.DLL, ADVAPI32.DLL, MSVCP120D.DLL and MSVCR120D.DLL

    I Just added Advapi32.lib, should I add the others also?

    Here is my working DEMO_LIB.pro file:
    @TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt

    SOURCES += demo.cpp

    HEADERS += demo.h

    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\inc
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\serial
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\system
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB\devices
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB\device_handles
    INCLUDEPATH += C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\ANT_LIB\software\USB

    LIBS += "C:\Users\Toto\Desktop\ANT_Windows_Library_Package_v3.2\Debug\lib\ANT_LIB.lib"
    LIBS += "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\User32.lib"
    LIBS += "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\AdvAPI32.Lib"@

    I will not have to ship these 2 libs with my application right? as all the windows system have it?
    Thank you a million time!



  • congrats! :)

    normally you don't need to deploy those dlls

    you missed my suggestion to use only once LIBS+= all libs space separated

    or

    LIBS+= lib1
    lib2
    ...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.