QtCreator vs cmd.exe (not equal)



  • Hi.
    I have example code and library (*.dll and *.a) for special device. In the reedme from this example there is advice:
    "compiled with
    g++ file1.c file2.c file3.cpp -l:libUSTROYSTVO.a -o result.exe" (I changed file names)
    I use OS Windows8.1 and Qt 5.4.1 for Windows 32-bit (MinGW 4.9.1, 856 MB) ( www.qt.io/download-open-source/ ). Using Qt 5.4 for Desktop (MinGW 4.9 32 bit) (console comand line) and command line
    g++ file1.c file2.c file3.cpp -l:libUSTROYSTVO.a -o result.exe
    I can create result.exe without errors and problems.
    But this example hasn't any project or make files. And I would like to use QtCreator for coding.
    When I try to create new empty project in QtCreator and add files from example, during build there are many errors.
    Could you give me advice, what should I do to create new project in QtCreator which works with example code like comand "g++ ...." in comand line?
    I suppose that QtCreator uses come default parametrs for building but g++ (in comand line) uses other ones.
    Thank you.



  • Hi,

    best way in Qt Creator for your case is probably to start from a "Project without Qt" -> "C++ Project". (maybe the names are slightly diffrent, I´m only guessing because my installation is german)

    Qt Creator will ask you for the kit, you want to use. To narrow where the errors come from, check that you configure for the kit containing the mingw4.9 compiler. If you don´t have a kit, create a new one.

    Copy the .c, .cpp and .a files to the project directory and edit your .pro file:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt
    
    SOURCES += file1.c \
               file2.c \
               file3.cpp
    
    HEADERS += youSureHaveSomeHeader.h \
               andMaybeOneMore.h
    
    LIBS +=  -llibUSTROYSTVO
    
    include(deployment.pri)
    qtcAddDeployment()
    

    Before compiling, you now need to run qmake!



  • Thank you, sneubert, for your advices.
    I am not sure that I have done exactly what you said, so I describe what I do.
    I choose C++ Project, With qmake, without Qt. There are 2 “similar” types: 1) C++ Project, With cmake, without Qt; 2) C++ Project, With qbs, without Qt. I suppose you mean “With qmake” isn’t?

    “… check that you configure for the kit containing the mingw4.9 compiler. If you don´t have a kit, create a new one.”
    Unfortunatly I don’t know how to check “mingw4.9 compiler”. I use default kit “KitSelection:Desktop Qt 5.4.1 MinGW 32bit”. And maybe, this parameter from Project Prpoperties can be interesting too
    qmake.exe ProjectTestNoQt.pro -r -spec win32-g++

    File *.pro have a bit difference
    LIBS += -L$$PWD/ -lUSTROYSTVO //not llibUSTROYSTVO and with pwd

    INCLUDEPATH += $$PWD/ // and this 2 strings(1)
    DEPENDPATH += $$PWD/ // and this 2 strings(2)

    And these strings was placed before "headers +=.. ". But I moved them to the end of file.
    include(deployment.pri)
    qtcAddDeployment()

    But however I have the same errors like I had early.
    Any ideas? )) I asked in third forum and still can’t solve my problem. (( So I am glad to see any your advice and idea.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What errors are you getting now ?



  • Thank you, SGaist , for your or attention.

    I have some identical errors in different parts of code: “undefined reference to” and “more undefined references to”
    For example:

    undefined reference to SomeOneFunc(_dictionary_*, char const*, int)' . more undefined references to SomeOneOtherFunc(dictionary, char const, int)' follow.

    This SomeOneFuncs are described in file1.c and file1.h and they have no deal with *.a. (I am not totally sure but looks like that is true. As I said before I am not author of this code.)
    Moreover there is exist one more error (last one)
    C:/ProgramFiles/QtMinGW/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: release/ FileMain.o: bad reloc address 0x14 in section `.text$ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8[_ZStplIcSt11char_traitsIcESaIcEESbIT_T0_T1_ERKS6_S8]'
    collect2.exe: error: ld returned 1 exit status
    mingw32-make[1]: *** [release\ProjectTest.exe] Error 1
    mingw32-make: *** [release] Error 2



  • The bad reloc address error you get, maybe caused by linking files compiled with different compilers.
    Do you build any part with a different compiler, or different version of gcc?
    Sometimes such errors are the result of having multiple mingw installation.
    You can compile from command line. Can you check the gcc dir with where g++?



  • When I compile from command line I use shortcut “Qt 5.4 for Desktop (MinGW 4.9 32 bit)” (from Start->Programs->Qt MinGW). This shortcut has properties (target object.. don’t sure how to translate it correct. But I suppose you know what I mean. ) This is one row
    C:\Windows\System32\cmd.exe /A /Q /K C:\ProgramFiles\QtMinGW\5.4\mingw491_32\bin\qtenv2.bat

    As I understand /A /Q /K is not important for compiler options. This is tenv2.bat file text: (4 rows)

    echo off
    echo Setting up environment for Qt usage...
    set PATH=C:\ProgramFiles\QtMinGW\5.4\mingw491_32\bin;C:\ProgramFiles\QtMinGW\Tools\mingw491_32\bin;%PATH%
    cd /D C:\ProgramFiles\QtMinGW\5.4\mingw491_32

    I don’t know how to check what QtCreator uses… Could you help me to know it?

    Moreover…When I saw first time Qt example I had OS Windows 8.1 and MS Visual Studio 2010 and I didn’t know what does g++ means. So I downloaded and installed Qt (5.4.1 MSVC 2010, 32bit) (qt-opensource-windows-x86-1.6.0-8-online, http://www.qt.io/download-open-source/). :) A bit later I had understood that it isn’t what I need :). After that I downloaded and installed http://sourceforge.net/projects/mingw/files/Installer/ mingw-get-setup.exe (86.5 kB) [with Basic Setup mingw-developer-tolkit mingw32-base mingw32-gcc-g++ msys-base]
    And the example works well with Windows cmd.exe without any bat-files or something else. But of course I set path to environment. After this I downloaded and installed Qt 5.4.1 for Windows 32-bit (MinGW 4.9.1, 856 MB) ( www.qt.io/download-open-source/ ). "G++..." command still works good from cmd.exe and g++ from previous installated MinGW (mingw-get-setup.exe).
    But I tried to delete path from environment for installed MinGW (mingw-get-setup.exe) and g++ stopped work with Windows cmd.exe But g++ command works with shortcut “Qt 5.4 for Desktop (MinGW 4.9 32 bit)”.
    Note: When I say “Windows cmd.exe ” I mean Start->Run->cmd.exe. Not shortcut with bat file and “path=…”. Moreover I don’t see in environment paths any folder for installed Qt 5.4.1 for Windows 32-bit (MinGW 4.9.1, 856 MB).
    I didn’t build compile etc *.a library from this example. And I haven't got source code for it or any information about how it had been created too.


  • Lifetime Qt Champion

    There's absolutely no need to install anything from MinGW since it comes as an option when you use the installer. Use that one. If you really want to do console development on Windows, then use the provided link to setup the console. Otherwise you'll have to do it by hand. Don't modify the PATH environment variable by hand, that's the shortest way to a world of trouble.



  • @SGaist said:

    There's absolutely no need to install anything from MinGW since it comes as an option when you use the installer. Use that one. If you really want to do console development on Windows, then use the provided link to setup the console. Otherwise you'll have to do it by hand. Don't modify the PATH environment variable by hand, that's the shortest way to a world of trouble.

    Ок. Thank you for advice. I understand. But what should I do now for create QtCreator project without errors? Should I uninstall all Qt and MinGW and reinstall then only Qt (MinGW version)?


  • Lifetime Qt Champion

    Since your install looks a bit messed up, yes, stat from clean



  • I have cleaned and reinstalled Qt. Moreover I installed Qt(MinGW) on other PC (without qt mingw etc before, but with MS VS2010).
    In both case there are the same errors I have described.


  • Lifetime Qt Champion

    The bad realloc error ? Or the kit error ?



  • @SGaist said:

    The bad realloc error ? Or the kit error ?

    Yes, realloc and undefined reference.
    undefined reference to SomeOneFunc(dictionary, char const, int)' .
    more undefined references to SomeOneOtherFunc(dictionary, char const, int)' follow.
    and
    ...bad reloc address 0x14 in section...
    I said about it before. Nothing changed after reinstall. And I have the same errors on other PC too.


  • Lifetime Qt Champion

    What symbols are missing ?



  • Thanks for advices.
    I have found the solve at Russian Qt forum.
    http://www.forum.crossplatform.ru/index.php?showtopic=10432
    Thanks to them.
    Problem can be solved by renaming all *.c file in project into *.cpp file.


Log in to reply
 

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