[Linker error] undefined reference to `CLSID_SpVoice'

After having spent the last few hours in deep frustration over Microsoft’s SAPI, I have finally made the decision to seek professional help. Google has failed me epically on this one, and so Kirupa C++ seems the way to go :wink:

My code (not actually mine, but an elegant mix of the code found on the MSDN SAPI 5.3 Tutorial, and http://www.gamedev.net/reference/articles/article1904.asp), looks like so:

// SAPI Sample 1.cpp : Defines the entry point for the console application.

#include <windows.h>
#include <Servprov.h>
#include <sapi.h>

int main ( int NumOfArguments, char** Argument )
    ISpVoice* Voice = NULL;                // The voice interface
    // Initialize COM
    CoInitialize ( NULL );

    // Create the voice interface object
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&Voice);
if( SUCCEEDED( hr ) )
        hr = Voice->Speak(L"Hello world", 0, NULL);

        // Change pitch
        hr = Voice->Speak(L"This sounds normal <pitch middle = '-10'/> but the pitch drops half way through", SPF_IS_XML, NULL );
        Voice = NULL;
    // Shutdown COM
    CoUninitialize ();

    return 0;

Since this is my first TTS Application, I wanted to start out simple, and just get things to work.

Nonetheless, compiling this code gives me the following errors:

[Linker error] undefined reference to IID_ISpVoice' [Linker error] undefined reference to CLSID_SpVoice’
ld returned 1 exit status
D:\DevCpp\Dev-Cpp\Makefile.win [Build Error] [Attempt4.exe] Error 1
I am using Dev-C++ version with a MingGW compiler.

I have added the SAPI Include directory to the Compiler Options, such that <sapi.h> is avaiable.

Since sapi.lib works badly with Dev-C++, I used the dlltool to create a libsapi.a from the sapi.dll file, I placed the .a file in the ‘lib’ folder of Dev-C++.

I then, under Project Settings, added the additional parameters to the linker “-lsapi” and “-lole32”.

Still, there seems to be a linker error? Did I forget about a header that defines CLSID_SpVoice and IID_ISpVoice? Hope someone can help :slight_smile: