How to use a third party function library package with source codes in my QT Project?



  • Hi, I am in troulbe with how to use a third parity function library package in my QT project.
    This function library is based on MSVC in windows and GCC in Linux, also I have all the source codes edited by standard C language. I think i have three methods to use this function library in my QT project.

    1. I can compile this function library in MSVC2005 and get the static library by using the solution included in the software package, also I can compile the function library with GCC ang get the static library by using the makefile included in the software package. So my question is Can I use these static libraries in my qt project? if can , how can i use ?

    2. Because i have all source codes in C language. I want to transport this funcion library to QT environment. I have tried to do this using minGW32 compiler in Windows, but I found a fatal error in Windows is when the program call many times malloc() function to get memory, a NULL pointer can be returned that means the system has not empty memory, so the program exit. I don't the reason, but this error can't be happened in MSVC.

    3. Also I tried to compile this source codes with MSVC compiler in QT environment, but I found a problem is all of souce files in my QT project is UTF-8 without BOM, the MSVC compiler can't compile these source file correctly because the MSVC compiler only can recognise the source file with UTF-8 BOM.

    So want to get everyone's help.
    Thanks!



  • To give an answer to question 2 we would need more informations about the source code and what happens where. However, this is actually not a Qt related question as it seems but maybe someone can help you anyway.

    ad 3. I would suggest to use plain ASCII files for source code. Otherwise you can use something like Notepad++ to add the BOM.

    ad 1. You have to add the library to you linker call. This depends on which kind of makefiles you use. Also you would need the include directories that the compiler knows which functions are available.



  • Ad1. my means is i can use this static library generated by the MSVC2005 in Windows in Qt creator and its compiler is mingw32? or I can use this static library geneated by GCC in Linux in Qt creator and its compiler is GCC?

    About question 2, I want to know the malloc function in mingGW32 and in MSVC is same ? what reason can cause to the NULL poniter?

    Thanks!



  • Hi,
    Your mixing a couple of things to make it work.
    First of all, when you have source code in C code, but you do need it compiled with a C++ compiler you must place:
    @
    (only in the header file)
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    ....your function declarations
    #ifdef __cplusplus
    }
    #endif
    @
    This will tell the compiler that the functions declared there is in fact a C piece of code, so C exceptions etc should be used, together with maybe different linker settings.
    That might solve your problems with MSVC compiling or MinGw compiling, both are C++ compilers, so they could have problems with your C-lib.

    The old library is only usable directly when you also use the same compiler for your project, so in this case the MSVC2005 compiler, but good luck finding Qt compiled with that compiler, so you need to manually compile Qt with that compiler. (might be lot's of work).

    So the most easy solution is to utilize the QLibrary class to interface with the library given. The only thing you then need is the dll and a header file of the library and you are able to interface with it.

    You malloc / Null pointer issue may be solved by increasing the stack size you get from the OS.



  • It is only possible to use a static lib (and normally also dynamic ones) which was compiled with the same compiler you use. That's why there are special versions of Qt for different compilers.

    What do you mean with "malloc function is the same"?



  • Because I got the different results. when I run the program generated by MSVC, everything is OK; But when I run the program generated by QT/minGW, malloc calling is wrong, in fact, two programs have the same source code and all run on Windows7 environment.


Log in to reply
 

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