PDA

View Full Version : Qt + Portmidi in Windows... libraries problem



hipogrito
24th April 2007, 06:16
Hi:

Qt 4 Open Source.

I've got Qt and Portmidi working under Linux.

Now, both things are cross-platform, so I'm trying to run the same program that runs in Linux, in Windows XP.


Portmidi libraries are prepared for Visual Studio. I create them: two .lib and one .dll using Visual Studio.

Qt Open Source for Windows uses mingw make.

The problem... I add the libraries in the project .pro file, but when I compile I get many undefined stuff, like this...


C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_pm_add_device]+0x166): undefined reference to `_RTC_CheckEsp'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.rtc$TMZ+0x0): undefined reference to `_RTC_Shutdown'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.rtc$IMZ+0x0): undefined reference to `_RTC_InitBase'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_Pm_CountDevices]+0x34): undefined reference to `_RTC_CheckEsp'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_Pm_GetDeviceInfo]+0x50): undefined reference to `_RTC_CheckEsp'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_none_get_host_error]+0x3b): undefined reference to `_RTC_CheckEsp'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_Pm_GetHostErrorText]+0x38): undefined reference to `_wassert'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_Pm_GetHostErrorText]+0x59): undefined reference to `_wassert'
C:/portmidi/pm_win/Debug/portmidi.lib(./pm_win/Debug/portmidi.obj)(.text[_Pm_GetHostErrorText]+0xad): undefined reference to `_RTC_CheckEsp'




Do I need to compile portmidi with mingw or is it just a problem in my .pro?


# File generated by kdevelop's qmake manager.
# -------------------------------------------
# Subdir relative project main directory: .
# Target is an application: Control

INCLUDEPATH += . C:/portmidi/pm_common C:/portmidi/porttime C:/portmidi/pm_win
LIBS += C:/portmidi/pm_win/Debug/portmidi.lib
LIBS += C:/portmidi/porttime/Debug/porttime.lib

include(manager.pro)
TARGET = Control

(I'm using 2 .pro... but this is the one with the interesting stuff for this example...)


Any ideas? :-)

Thanks!

Regards
Hipo

fullmetalcoder
24th April 2007, 21:26
Looks like a linker error... Maybe your Portmidi library brings some extra dependencies which are not notified to the linker by default (which you should thus add by hand in the pro file).

yso
19th June 2009, 01:01
I'd encountered recently a similar problem. Here are the explanation of
its root and the recipe of the workaround. May be it would be useful to somebody.

The debug version of the external MyLibrary.lib has been compiled by means of
Visual Studio .NET 2003. When it is linked with the Qt project unresolved
references to _RTC_CheckEsp etc. stuff appeared. These functions implement
Runtime Checks and were introduced by Microsoft into C Runtime Library
(i.e. CRT) beginning from Visual Studio .NET.

MinGW uses earlier version of CRT - Visual Studio 6.0 to be precise -
(implemented by MSVCRT.DLL) so there is nothing astonishing in unresolved
references.

I had attempted to uncheck the C/C++/Code Generation/Basic Runtime checks in
MyLibrary Visual Studio project but references to _RTC_Initialize and _RTC_Terminate
persisted as unresolved. I had attempted also to link additionally static
library LIBCMTD.LIB. Unresolved references have gone but as one may expect
duplicated name mainCRTStartup appeared.

Then I had found out that RunTmChk.lib allows to implement Runtime Checks
without C Runtime Library - see http://msdn.microsoft.com/en-us/library/azff25ez.aspx.
(In my case MinGW uses C Runtime Library but for my goals I may successfully
imagine that no C Runtime Library presents.)
One needs to include RunTmChk.lib into .pro-file and implement _CRT_RTC_INIT function
in one's Qt code. _CRT_RTC_INIT should install error reporting function.
As explained in comments within file RTCAPI.H error reporting function may be NULL.

RECIPE. So workaround is:

1. Add to .pro-file lines:

MSVC2003_LIBPATH = "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib\"
win32 {
if (DebugBuild) {
LIBS += -LD:\Projects\MyLibrary\Debug\ -lMyLibrary
LIBS += -L$$MSVC2003_LIBPATH -lRunTmChk
}
if (ReleaseBuild) {
LIBS += -LD:\Projects\MyLibrary\Release\ -lMyLibrary }
}

2. Add to the Qt project new .cpp-file containing lines:

extern "C" {
#define NULL 0
typedef int (__cdecl *_RTC_error_fn)(int, const char *, int, const char *, const char *, ...);
_RTC_error_fn _CRT_RTC_INIT(void *res0, void **res1, int res2, int res3, int res4);
}
_RTC_error_fn _CRT_RTC_INIT(void *res0, void **res1, int res2, int res3, int res4)
{
return NULL;
}

Now all the problems caused by the RTC would go. Of course, this approach cannot help
with other Runtime Library extras like _wassert.

Regards
Yuri Osipov