1

I've built and included the RtAudio library in a project, but when I try to build the project itself, I get errors:

RtAudio.cpp:-1: error: undefined reference to `CoInitialize@4'
RtAudio.cpp:-1: error: undefined reference to `CoUninitialize@0'
:-1: error: D:/Qt/Qt5.3.2/Tools/QtCreator/bin/teslib/../../../../../../lib/rtaudio-4.1.1//librtaudio.a(RtAudio.o): bad reloc address 0x17 in section `.text.unlikely'
collect2.exe:-1: error: error: ld returned 1 exit status

The third error message looks suspicious, what does this mean?

bad reloc address 0x17 in section `.text.unlikely'

I wasn't able to build the library with the MinGW bundled with Qt, so I built it with the same major version (4.8), is it possible that the library is incompatible with Qt due to being built with a different minor version of GCC?

1 Answers1

3

CoInitialize and CoUnitialize are defined in the library Ole32.lib. Make sure the library is included in the linker library list.

Wayne Tanner
  • 1,346
  • 11
  • 18
  • But why is that? My project doesn't reference those functions, the library does, and the library is already compiled. Why do they need to be included in my project as well? –  Nov 21 '14 at 20:20
  • Also, I have no such file on my system whatsoever. I have a `libole32.a`. And adding that resulted in a rain of new `undefined reference to` errors. –  Nov 21 '14 at 20:23
  • 2
    The obvious conclusion is that the RtAudio library uses COM for something. The fact that you successfully compiled it does not imply that you have all the dependencies necessary to actually link it into an application an use it. – nobody Nov 21 '14 at 20:29
  • @AndrewMedico - that obvious conclusion doesn't help me at all. The library has already compiled successfully, adding the ole32 library that I have on my system to my project doesn't help it but breaks it tremendously more... –  Nov 21 '14 at 20:32
  • Although the library is compiled, it is not linked. It only has references to the functions it needs that are not in the library. If you use nm to dump the symbol table of the library you will see the externally linked symbols. The final linking isn't taking place until you try to build the application at which time the link errors occur. If adding libole32.a causes a bunch of undefined references, that just means that it's dependencies are not being linked yet. On Windows, COM/OLE pulls in a good bit of other stuff. – Wayne Tanner Nov 21 '14 at 20:54
  • @WayneTanner - is there any tool to list me all libraries I need to include? Cuz adding libole32 results in a LOT of new errors, all from a `crtexe.c` file. –  Nov 21 '14 at 21:04
  • Unfortunately, not that I know of offhand. I've had to resort to the brute force method of searching the name of the undefined method on MSDN to figure out which library it is in. The good news, is that typically each one you do fixes many errors (all the functions that were in that library). Common ones that are frequently needed are kernel32.lib, user32.lib, gdi32.lib, ole32.lib, oleaut.lib. Kernel32 and user32 have a lot of core Windows functions, gdi32 contains GUI related stuff, ole32 and oleaut contain the COM related stuff. – Wayne Tanner Nov 21 '14 at 22:24
  • @WayneTanner - what about that `bad reloc` error? I read it is often the product of incompatible libraries? Maybe that's the problem? BTW the new errors after including libole32 are not MS related but MINGW, and searching on the internet, I couldn't find anything to suggest which libraries I should include to resolve this... Such as `mingw_initcharmax, mingw_app_type` and so on... –  Nov 22 '14 at 10:57
  • It is possible that it is related to the version differences you mentioned originally. I use MinGW some but haven't had that particular problem. Generally, I haven't had problems between minor versions but that is no guarantee that it isn't a problem for your particular situation. – Wayne Tanner Nov 22 '14 at 16:27