gpt4 book ai didi

c++ - 对 _imp__CoInitialize@4 的 undefined reference

转载 作者:太空狗 更新时间:2023-10-29 23:41:59 25 4
gpt4 key购买 nike

我正在查看 Virtual Box 示例。我很快尝试触发以下代码,但我收到了与 COM 相关的错误。

    //#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 `_imp__CoInitialize@4'
collect2: ld returned 1 exit status

最佳答案

尝试

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

引用

CoInitialize Function

您需要链接 ole32.dll(“-lole32”)。为了链接到它,您需要在搜索路径中安装它的导入库 (ole32.lib)。我假设您可能需要为此安装 Windows SDK。

关于c++ - 对 _imp__CoInitialize@4 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6705396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com