Nominate our 2022 Qt Champions!

QtC doesn't call .lib file generating

  • I need to create one SUBDIRS type project with a number of dll sub-projects and one console app to test them (for some reasons I can't use unit tests project type).
    So I've created these projects and added library projects into console one from context menu - add library

    MSVC2013 64 bit

    however a linker shows me an error:
    :-1: error LNK1104: cannot open file '<plugin_x>.lib'
    where plugin_x is a one of library projects

    so seems QtC didn't add into library projects a generating .lib files (import library for a linking with dll)

    is this known issue of QtC or I'm doing something wrong?

  • Lifetime Qt Champion


    What is the exact problem with unit tests ?

    Can you show your project pro files ?

  • found the solution in vc compiler documentation

    that was because I've only created empty projects:
    dll project and console project (and added dll as a library into console)

    .lib file has not been generated because of project was empty and nothing to export (and link)
    added __declspec(dllexport) to class definition and .lib file was generated and correctly linked with console application

    P.S. I know that export classes is a bad practice and we have to prefer the export of plain functions instead
    but that was a client's requirement

  • Lifetime Qt Champion

    Oh yes, I've been bitten by that one when changing from static to dll...

    You can have a look at Qt's macro to help you export your classes in a cross platform way.

    It really depends on your use case. Take Qt for example, is it exporting only functions ?

  • I don't use Qt lib here, just a QtC,
    in other hand , this piece of code can be unportable and be built MSVC only.
    you see this - very unportable solution - using class exporting , but that is a client's requirement

  • Lifetime Qt Champion

    You don't need to use specifically these macros but you can write your own based on them so that you're future proof (client's requirement can unpredictably change)

  • I'm using something typical, looks working for me

    #ifdef EXP_STL
    #    define DECLSPECIFIER __declspec(dllexport)
    #    define EXPIMP_TEMPLATE
    #    define DECLSPECIFIER __declspec(dllimport)
    #    define EXPIMP_TEMPLATE extern
    EXPIMP_TEMPLATE template class DECLSPECIFIER std::basic_string<char>;

    where EXP_STL is defined for dll and undefined for exe

    the only issue I faced some time ago is an exporting std::list of std::unique_ptr
    unique_ptr has move init semantics but list requires copy ctor
    I was using emplace_back for elements filling up and that was working for single project but for the sharing this object between dll and exe (function in dll returns this list to the caller from exe)
    like this:
    EXPIMP_TEMPLATE template class DECLSPECIFIER std::list<std::unique_ptr<my_class>>;

    raise the error - something about deleted copying ctor of unique_ptr, it'd look reasonable in case of list using
    but here - the declaration only!
    I can't understand why - this is the only declaration. if I remove declspec this will be built correctly….

    [edit: Added missing coding tags: 3 ` before and after SGaist]

Log in to reply