Results 1 to 10 of 10

Thread: qmake build lib without automatic lib prefix

  1. #1
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default qmake build lib without automatic lib prefix

    Forum is a little hard to search so sorry if this has been asked before

    I am trying to create a .pro file that can used used on multiple platforms to build a library (MyLib.so,MyLib.dll,...). Seems fairly easy with qmake and it all works, except that the name of the library has a prefix 'lib' when built on a *nix system (libMyLib.so). And this might be okay except for the fact that I am using QLibrary to load the library and trying to use a common name: Qlibrary mylib("MyLib"). While QLibrary does try different extensions (.so,.dll), it does not try to add a 'lib' prefix. So is there a way to have qmake build a lib with a name that I specifically want?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qmake build lib without automatic lib prefix

    You can force it to do it but it is a bad idea. It is a well established scheme to prefix libraries on Unix with "lib". It's much easier to convince QLibrary to use a proper name:

    Qt Code:
    1. QLibrary loader;
    2. #ifdef Q_OS_UNIX
    3. loader.setFileName("libMyLib");
    4. #else
    5. loader.setFileName("MyLib");
    6. #endif
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: qmake build lib without automatic lib prefix

    While I agree its a well established scheme on *nix systems to prefix with "lib", it should not be forced on you. If there is a legitimate need to have a library be named a certain way based on project need, you should be able to do that. Knowing that qmake forces that, I can work around it . . . mainly for project use of loading library at runtime with QLibrary.

    It also seems that qmake will use the VERSION on a windows build to tack on a version major number to the library name. I had to work around that as well . . . good thing that if you leave it blank it will not generate one on its own.

    So now I have the following in my .pro file to build the same name across my platforms [linux/mac/windows], all with lib- prefix:

    Qt Code:
    1. win32 {
    2. TARGET = lib$$qtLibraryTarget($$TARGET)
    3. } else {
    4. TARGET = $$qtLibraryTarget($$TARGET)
    5. VERSION = $$system(awk \'/const VERSION/ { print substr( $6, 3 ) }\' main.cpp)
    6. # clean up shared libs as version number changes
    7. QMAKE_DISTCLEAN += *.so*
    8. }
    9. TEMPLATE = lib
    To copy to clipboard, switch view to plain text mode 
    The only ugliness that I have seen from this is that in a mingw build on windows, there is a temporary library .a that is created before making the .dll that qmake forces to have a lib prefix, so the temp name is liblibNAME.a. Since it is temp, I am not worrying to much about that.

    My description was for a simple case. Eventually the name will be changed so the #if method will not work. I guess I could have subclassed QLibrary to try additional prefixes, but this seems to work for now.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by mcarter View Post
    Knowing that qmake forces that, I can work around it
    Nothing forces it. It's just the default setting for qmake.

    Eventually the name will be changed so the #if method will not work.
    It will work if you do it properly (e.g. using defines).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by mcarter View Post
    It also seems that qmake will use the VERSION on a windows build to tack on a version major number to the library name.
    It does this for a very good reason: DLL hell is not much fun. The version number allows you to distinguish libraries built with incompatible interfaces.

  6. #6
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by ChrisW67 View Post
    It does this for a very good reason: DLL hell is not much fun. The version number allows you to distinguish libraries built with incompatible interfaces.
    I agree DLL hell is not fun at all. I like that fact the VERSION is embedded into the DLL. However, I do not want to be forced (hard-coded in the qmake source code if VERSION is used) to a specific naming convention. It would nice to figure out how to get the version back into dll without using VERSION.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by mcarter View Post
    It would nice to figure out how to get the version back into dll without using VERSION.
    This seems a bit contradictory. By the way, is there a specific reason why you are using QLibrary instead of other solutions of using a library in your program?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by mcarter
    It would nice to figure out how to get the version back into dll without using VERSION.
    Quote Originally Posted by wysota View Post
    This seems a bit contradictory. By the way, is there a specific reason why you are using QLibrary instead of other solutions of using a library in your program?
    It sounded strange even as I wrote it. Since using VERSION in the .pro file causes qmake to append the major number to the library name, I wanted to avoid using it, but qmake uses the VERSION to embed into dll. I wanted to do the latter and avoid the library name change.

    For my application, I can connect to multiple sources. Each of the sources is a "library" that implements the application API to gather data for displaying. The app is to be used on multiple platforms all using the same config file. That is the reason for one common name across platforms.

    I am using QLibrary to load the library at run-time. Using Qt, I thought that was the easiest to implement. Everything was there for cross-platform. I was trying to avoid writing my own. Is there a better solution?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by mcarter View Post
    Since using VERSION in the .pro file causes qmake to append the major number to the library name, I wanted to avoid using it, but qmake uses the VERSION to embed into dll. I wanted to do the latter and avoid the library name change.
    That doesn't avoid DLL hell (at least not without a dedicated manifest).

    For my application, I can connect to multiple sources. Each of the sources is a "library" that implements the application API to gather data for displaying. The app is to be used on multiple platforms all using the same config file. That is the reason for one common name across platforms.

    I am using QLibrary to load the library at run-time. Using Qt, I thought that was the easiest to implement. Everything was there for cross-platform. I was trying to avoid writing my own. Is there a better solution?
    Wouldn't it be easier to use plugins? QLibrary requires you to resolve all the symbols manually. You don't have to do that with QPluginLoader (which internally uses QLibrary). The additional benefit is that if you build a library as a plugin, it solves all your other problems automatically -- qmake doesn't prefix it with "lib" on Unices and (afair) doesn't append the version number on Windows.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Nov 2009
    Location
    San Antonio, TX
    Posts
    69
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt Jambi
    Platforms
    Unix/X11 Windows

    Default Re: qmake build lib without automatic lib prefix

    Quote Originally Posted by wysota View Post
    Wouldn't it be easier to use plugins? QLibrary requires you to resolve all the symbols manually. You don't have to do that with QPluginLoader (which internally uses QLibrary). The additional benefit is that if you build a library as a plugin, it solves all your other problems automatically -- qmake doesn't prefix it with "lib" on Unices and (afair) doesn't append the version number on Windows.
    Alas, these libraries are not Qt based. With the api, the libraries can be created by any number of developers, who may or may not have Qt. The lowest common denominator was not to wrap the library in Qt. That may change in the future, but for now I do not think I can use QPluginLoader unless it is purely Qt-based.

Similar Threads

  1. how do I set the PREFIX inside the project file?
    By hakermania in forum Newbie
    Replies: 3
    Last Post: 19th August 2011, 21:09
  2. How to check in c app what has been it's installation prefix?
    By pielas in forum General Programming
    Replies: 2
    Last Post: 14th July 2010, 09:19
  3. Automatic snapshots/nightly build system/scripts
    By BastiBense in forum General Programming
    Replies: 1
    Last Post: 11th March 2009, 10:40
  4. Automatic translation in qmake's project?
    By mchara in forum Qt Programming
    Replies: 7
    Last Post: 11th July 2008, 15:11
  5. qmake to build both 32-bit and 64-bit
    By lni in forum Qt Programming
    Replies: 8
    Last Post: 12th December 2006, 19:35

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
  •  
Qt is a trademark of The Qt Company.