2011-07-15 11 views
2

私はVirtual Boxの例を見ていました。私はすぐに次のコードを起動しようとしましたが、COMに関連するエラーが発生しました。_imp__CoInitialize @ 4への未定義参照

 

    //#include "VirtualBox.h" 

    #include "rpc.h" 
    #include 

    int main(int argc, char *argv[]) 
    { 
     HRESULT rc; 
    //  IVirtualBox *virtualBox; 

      do 
      { 
       /* Initialize the COM subsystem. */ 
       CoInitialize(NULL); 

       /* Instantiate the VirtualBox root object. */ 
      // rc = CoCreateInstance(CLSID_VirtualBox,  /* the VirtualBox base object */ 
      //      NULL,     /* no aggregation */ 
      //       CLSCTX_LOCAL_SERVER, /* the object lives in a server process on this machine */ 
       //      IID_IVirtualBox,  /* IID of the interface */ 
      //       (void**)&virtualBox); 

       if (!SUCCEEDED(rc)) 
       { 
        printf("Error creating VirtualBox instance! rc = 0x%x\n", rc); 
        break; 
       } 


      } while (0); 

      //CoUninitialize(); 
      return 0; 
     printf("Hello, world\n"); 

     return 0; 
And the error I have got is: 
<pre> 
E:\vbox\mscom\samples>g++ -I E:\vbox\mscom\include -Wall helloworld.cpp -o helloworld.exe 
helloworld.cpp: In function 'int main(int, char**)': 
helloworld.cpp:26: warning: format '%x' expects type 'unsigned int', but argument 2 has type 'HRESULT' 
helloworld.cpp:24: warning: 'rc' is used uninitialized in this function 
C:\Users\AKANTH~1.ADO\AppData\Local\Temp\ccCmOygi.o:helloworld.cpp:(.text+0x1e): undefined reference to `[email protected]' 
collect2: ld returned 1 exit status 

答えて

9

CoInitialize Function

リファレンス

g++ -I E:\vbox\mscom\include -Wall helloworld.cpp -o helloworld.exe -lole32 -loleaut32 

を試してみてくださいあなたは( "-lole32")をOLE32.DLLリンクする必要があります。これにリンクするには、そのライブラリ(ole32.lib)をインストールしておき、検索パスにそのライブラリをインストールする必要があります。私はそれのためにWindows SDKがインストールされている必要があるかもしれないと仮定します。

+0

-lole32 -loleaut32 –

+0

拡張回答 – sehe

関連する問題