Why library name gets an additional 0 in its name?

2019-07-11 18:49发布

I have this tiny Qt project with a project file like this:

TEMPLATE = lib
TARGET = record32
VERSION = 0.0.1
DEPENDPATH += .
INCLUDEPATH += .

CONFIG += shared
SOURCES += recorder.cpp
HEADERS += recorder.h

When I compile a library from it by qmake && nmake, it results into files

record32.obj
record320.lib
record320.dll
...

Why is that additional 0 added to the lib and dll names?

The generated makefiles seem not be appending it but rather just assume it, in Makefile.Release it just says:

####### Files

SOURCES       = recorder.cpp release\moc_recorder.cpp
OBJECTS       = release\recorder.obj release\moc_recorder.obj
DIST          = 
QMAKE_TARGET  = recorder
DESTDIR        = release\ #avoid trailing-slash linebreak
TARGET         = record320.dll
DESTDIR_TARGET = release\record320.dll

How can I prevent it and name my libraries as I wish?

(Note that manually fix the makefile.release isn't a accetable solution)

3条回答
啃猪蹄的小仙女
2楼-- · 2019-07-11 19:03

Useful trick:

VERSION = 0.0.1
win32:TARGET_EXT = .dll

With this you will get:

  • on Linux: librecord.so, ..., librecord.so.0.0.1
  • on Windows: record.dll
查看更多
迷人小祖宗
3楼-- · 2019-07-11 19:08

It comes from the first part of VERSION. The "lib" TEMPLATE is adding it.

IMO it's a good idea to include it in the library name, since it avoids the infamous "DLL Hell" that happens on Windows where this convention is not followed consistently... By naming the library files to include the major version number, users can have multiple versions installed and programs will use the correct versions at run time. The DLL version doesn't neccesarily need to be the same as the overall project release version. On Linux and OSX the versions are appended to the filename (e.g. librecorder.so.0.0.1)

[If using Visual C++ I also always add a tag indicating what version of Visual C I used since code generated by the different versions are largely incompatible also.]

Maybe you can just omit the definition of VERSION to disable this behavior, but I can't verify that right now for Windows (On Linux, where shared libraries always have version numbers, it just assumes version 1.0.0.)

查看更多
可以哭但决不认输i
4楼-- · 2019-07-11 19:10

Try this:

CONFIG += skip_target_version_ext
查看更多
登录 后发表回答