Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Windows: linking debug vs. release .libs, strange error!



  • I create a DLL, both debug and release versions, but they have the same name (CFLite.lib), in debug/rlease directories
    0_1535742526562_Screen Shot 2018-08-31 at 12.07.27 PM.png
    0_1535741881413_Screen Shot 2018-08-31 at 11.56.48 AM.png
    I then create a test app that links to it, both debug and release, which have different names ("CFTest" and "CFTest Debug")
    0_1535741923698_Screen Shot 2018-08-31 at 11.57.25 AM.png
    0_1535741937748_Screen Shot 2018-08-31 at 11.57.46 AM.png
    in my qmake file, i specify them to link to "CFLite", in debug/release directories, the name INSIDE the directory is the same (as mentioned above).

    REL_DIR_CFLITE = win-CFLite$${BUILD_TYPE_SUFFIX}/$${build_type}/
    message(CFLite Dir: $$REL_DIR_CFLITE)
    LIBS += -L$${DIR_OPENCFL}Qt/$${REL_DIR_CFLITE} -lCFLite
    

    the message produced for release is:

    Project MESSAGE: CFLite Dir: win-CFLite/release/
    

    for debug is:

    Project MESSAGE: CFLite Dir: win-CFLite Debug/debug/
    

    so we know that's all set up nicely.

    Linking the release app works. Attempting to link debug fails with this message:

    LINK : fatal error LNK1104: cannot open file 'CFLite_Debug.lib'
    

    But nowhere do i specify that the name of that lib ends with "_Debug"

    indeed, in the generated make file ".../qt/win-CFTest Debug/Makefile.Debug", it specifies the correct path and name:

    /LIBPATH:"..\..\..\..\CF\opencflite-476.17.2\Qt\win-CFLite Debug\debug" "..\..\..\..\CF\opencflite-476.17.2\Qt\win-CFLite Debug\debug\CFLite.lib"
    

    which you can see in the first screen shot is in fact the correct path.

    So WHY is the linker adding "_Debug" to the end of the file name for that lib? Where does it get that name?



  • My apologies. I found this in my code:

    #if OPT_WINOS
    	#ifdef kDEBUG
    		#define		kCFLiteLib	"CFLite_Debug"
    	#else
    		#define		kCFLiteLib	"CFLite"
    	#endif
    
    	#pragma comment(lib, kCFLiteLib ".lib")
    #endif
    

    which explains the whole problem, that was leftover from a different compiler, and i no longer need it!


  • Lifetime Qt Champion

    Hi,

    Can you show your complete .pro file ?



  • QT -= qtcore
    QT -= gui
    
    message(------------------------------)
    
    #for(var, $$list($$enumerate_vars())) {
    #    message($$var)
    #    message($$eval($$var))
    #	message(------)
    #}
    
    TEMPLATE = app
    
    DEFINES += QT_DEPRECATED_WARNINGS
    DEFINES += _QT_
    
    DEFINES += _CFTEST_
    DEFINES += _MIN_CF_
    DEFINES += _JUST_CFTEST_
    CONFIG += c++11
    
    macx {
    	DEFINES += OPT_MACOS=1
    
    	# on mac, you can ONLY build 64bit, there is no 32bit compiler
    	QMAKE_TARGET.arch = x86_64
    } else {
    	DEFINES += OPT_WINOS=1
    
    	# options: openssl | libressl
    	ssl_edition = libressl
    }
    
    contains(QMAKE_TARGET.arch, x86_64) {
    	DEFINES += __LP64__=1
    	build_depth = 64
    } else {
    	build_depth = 32
    }
    
    CONFIG(release, debug|release) {
    	build_type = release
    	build_Type = Release
    	BUILD_TYPE_SUFFIX = ""
    } else {
    	build_type = debug
    	build_Type = Debug
    	DEFINES += kDEBUG
    	BUILD_TYPE_SUFFIX = " Debug"
    }
    
    message(build_type: $${build_type})
    message($${TARGET} $${build_depth}bit)
    
    DIR_PROJ	= ../../
    DIR_CFTEST	= $${DIR_PROJ}../
    DIR_SOURCE	= $${DIR_CFTEST}source/
    DIR_CF		= $${DIR_CFTEST}../CF/
    
    macx {
    	QMAKE_LFLAGS += -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
    	LIBS += -framework Carbon
    	LIBS += -framework CoreFoundation
    	LIBS += -framework ApplicationServices
    
    	QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
    
    	QMAKE_CXXFLAGS_WARN_ON += -Wall -Wno-unused-parameter
    
    	SOURCES += \
    		$${DIR_CF}CFNetwork/NetServices/CFNetworkAddress.c
    
    	HEADERS += \
    		$${DIR_CF}CFNetwork/include/CFNetwork/CFNetworkAddress.h
    
    } else {
    	DEFINES += __WIN32__
    	DEFINES += _WINDOWS
    	DEFINES += WIN32
    	DEFINES += _WIN32
    	DEFINES += _UNICODE
    	DEFINES += UNICODE
    	DEFINES += _SCL_SECURE_NO_WARNINGS
    	DEFINES += _CRT_SECURE_NO_WARNINGS
    
    	# calling convention: __cdecl
    	QMAKE_CFLAGS += /Gd
    	QMAKE_CXXFLAGS += /Gd
    
    	DIR_OPENCFL = $${DIR_CF}opencflite-476.17.2/
    
    	CONFIG(release, debug|release) {
    		# mulithread dynamic link
    		QMAKE_CXXFLAGS += /MD
    		LIBS += -lmsvcrt
    	} else {
    		# mulithread dynamic link
    		QMAKE_CXXFLAGS += /MDd
    		DEFINES += _DEBUG
    		LIBS += -lmsvcrtd
    	}
    
    	REL_DIR_CFLITE = win-CFLite$${BUILD_TYPE_SUFFIX}/$${build_type}/
    	message(CFLite Dir: $$REL_DIR_CFLITE)
    	
    	LIBS += -L$${DIR_OPENCFL}Qt/$${REL_DIR_CFLITE} -lCFLite
    	LIBS += -lWs2_32 -lkernel32 -lole32 -loleaut32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -luuid -lodbc32 -lodbccp32
    	LIBS += -lcomctl32
    
    	INCLUDEPATH += $${DIR_OPENCFL}dist/include
    	DEPENDPATH	+= $${DIR_OPENCFL}dist/include
    	INCLUDEPATH += $${DIR_CF}CFNetwork/include
    }
    
    QMAKE_POST_LINK += python $${DIR_PROJ}post_build_cftest.py QT $$build_depth $$TARGET $$ssl_edition
    
    INCLUDEPATH += $${DIR_SOURCE}
    INCLUDEPATH += $${DIR_SOURCE}headers
    INCLUDEPATH += $${DIR_SOURCE}shared
    INCLUDEPATH += $${DIR_SOURCE}main
    INCLUDEPATH += $${DIR_CF}CFNetwork/include/CFNetwork
    
    SOURCES += \
    	$${DIR_SOURCE}shared/CCFData.cpp \
    	$${DIR_SOURCE}shared/CCFError.cpp \
    	$${DIR_SOURCE}shared/CFBonjour.cpp \
    	$${DIR_SOURCE}shared/CFUtils.cpp \
    	$${DIR_SOURCE}shared/CNetHTTP.cpp \
    	$${DIR_SOURCE}shared/SuperString.cpp \
    	$${DIR_SOURCE}main/CFNetworkTest.cpp \
    	$${DIR_SOURCE}main/CFTest.cpp \
    	$${DIR_SOURCE}main/CFTestUtils.cpp \
    	$${DIR_SOURCE}main/CWebServerTest.cpp \
    	$${DIR_SOURCE}main/main.cpp
    
    HEADERS += \
        $${DIR_SOURCE}shared/CCFData.h \
        $${DIR_SOURCE}shared/CCFError.h \
        $${DIR_SOURCE}shared/CFBonjour.h \
        $${DIR_SOURCE}shared/CFUtils.h \
        $${DIR_SOURCE}shared/CNetHTTP.h \
        $${DIR_SOURCE}shared/SuperString.h \
    	$${DIR_SOURCE}main/CFNetworkTest.h \
    	$${DIR_SOURCE}main/CFTest.h \
    	$${DIR_SOURCE}main/CFTestUtils.h \
    	$${DIR_SOURCE}main/CWebServerTest.h \
    	$${DIR_SOURCE}headers/stdafx.h
    

  • Lifetime Qt Champion

    Looks fine...

    Do you have the same issue if you use qmake directly from the command line ?

    By the way, which version of Qt are you using ? With which version of Qt Creator ?



  • i don't know how to use it from command line.

    i'm on QtCreator 4.7.1, with Qt 5.11.1


  • Lifetime Qt Champion

    IIRC, when you installed Qt, you should have gotten an entry in your Start menu with a set of command prompt shortcuts. Are they there ?



  • yes i have that, i click it and get this:

    Setting up environment for Qt usage...
    Remember to call vcvarsall.bat to complete environment setup!
    
    C:\Users\davec\Developer\Qt\5.11.1\msvc2017_64>
    

    Should i be worried about that "vcvarsall.bat" thing?

    I'm assuming you're asking about the command line just as a test (to eliminate variables), and not as a solution. Sorry i don't know anything about doing it that way.



  • My apologies. I found this in my code:

    #if OPT_WINOS
    	#ifdef kDEBUG
    		#define		kCFLiteLib	"CFLite_Debug"
    	#else
    		#define		kCFLiteLib	"CFLite"
    	#endif
    
    	#pragma comment(lib, kCFLiteLib ".lib")
    #endif
    

    which explains the whole problem, that was leftover from a different compiler, and i no longer need it!


  • Lifetime Qt Champion

    Glad you found out and thanks for sharing !


Log in to reply