linking error for Bstr

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
cheburash
Posts: 5
Joined: 15. Jul 2016, 03:40

linking error for Bstr

Post by cheburash »

I'm trying to use com::Bstr class as suggested by SDK guide, my env: C++, Linux.
Getting errors:
,
../build/vbrun/vbrun/vb_helpers.o: In function `com::Bstr::raw() const':
vb_helpers.cpp:(.text._ZNK3com4Bstr3rawEv[com::Bstr::raw() const]+0x20): undefined reference to `com::g_bstrEmpty'
../build/vbrun/vbrun/vb_helpers.o: In function `com::Bstr::cleanup()':
vb_helpers.cpp:(.text._ZN3com4Bstr7cleanupEv[com::Bstr::cleanup()]+0x23): undefined reference
to `SysFreeString'
../build/vbrun/vbrun/vb_helpers.o: In function `com::Bstr::copyFrom(char const*)':
vb_helpers.cpp:(.text._ZN3com4Bstr8copyFromEPKc[com::Bstr::copyFrom(char const*)]+0x26): undefined reference to `com::Bstr::copyFromN(char const*, unsigned long)'

I am already linking with VBoxXPCOM.so VBoxRT.so.
Any other library I should link to?

Thanks
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: linking error for Bstr

Post by noteirak »

As specified in the API Forum guidelines, please include a standalone source code that produce that error.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
cheburash
Posts: 5
Joined: 15. Jul 2016, 03:40

Re: linking error for Bstr

Post by cheburash »

#include <nsMemory.h>
#include <nsString.h>
#include <nsIServiceManager.h>
#include <nsEventQueueUtils.h>

#include <nsIExceptionService.h>

#include <VBox/com/com.h>
#include <VBox/com/string.h>
#include <VBox/com/array.h>
#include <VBox/com/Guid.h>
#include <VBox/com/ErrorInfo.h>
#include <VBox/com/errorprint.h>

#include <VBox/com/VirtualBox.h>


/*
* VirtualBox XPCOM interface. This header is generated
* from IDL which in turn is generated from a custom XML format.
*/
#include "VirtualBox_XPCOM.h"

#include <iprt/stream.h>


nsCOMPtr<IVirtualBox> g_virtualBox;


int main(int argc, char * argv[])
{
nsresult rc;
IMachine * machine = NULL;
IVirtualBox * virtualBox = (IVirtualBox *) g_virtualBox;

com::Bstr ucName(argv[1]);

rc = virtualBox->FindMachine(ucName.raw(), &machine);

if (NS_FAILED(rc))
{
fprintf(stderr, "FindMachine failed 0x%x\n", rc);
goto End;
}

End:
return 0;
}
cheburash
Posts: 5
Joined: 15. Jul 2016, 03:40

Re: linking error for Bstr

Post by cheburash »

build it:

g++ -DRT_OS_LINUX -DVBOX_WITH_XPCOM -DIN_RING3 -DVBOX_WITH_XPCOM_NAMESPACE_CLEANUP -I../../src/VirtualBox-4.3.34/sdk/bindings/xpcom/include -I../../src/VirtualBox-4.3.34/sdk/bindings/xpcom/include/nsprpub -I../../src/VirtualBox-4.3.34/sdk/bindings/xpcom/include/string -I../../src/VirtualBox-4.3.34/sdk/bindings/xpcom/include/xpcom -I../../src/VirtualBox-4.3.34/sdk/bindings/xpcom/include/ipcd -I../../src/VirtualBox-4.3.34/include -Wall -fshort-wchar -c test.cpp

g++ -Wl,-rpath /usr/lib/virtualbox/ -o tst /usr/lib/virtualbox/VBoxXPCOM.so /usr/lib/virtualbox/VBoxRT.so test.o
cheburash
Posts: 5
Joined: 15. Jul 2016, 03:40

Re: linking error for Bstr

Post by cheburash »

sdk 4.3
klaus
Oracle Corporation
Posts: 1133
Joined: 10. May 2007, 14:57

Re: linking error for Bstr

Post by klaus »

First of all: why do you still use VirtualBox 4.3? It's unsupported for over 6 months now, and we can only encourage everyone to quickly move away from it. Use 5.0 (or 5.1) ASAP.

Back to your unclear issue: This can be hardly called standalone. Your're heavily referring to the VirtualBox tree, which normal SDK use doesn't need. The SDK is pretty much standalone for normal use.

Bstr is part of the 'glue' library, which isn't yet available as part of the SDK (it has been planned to change this for about 6 years, but we always don't find time and forget). I know that the SDK manual talks about Bstr and Utf8Str (and smart pointers), but this isn't available until the 'glue' library makes it to the SDK.

Can you say a bit more about your context (don't need nitty gritty details, just roughly what you want to achieve), because you seem to be pushing the limits of the SDK?
cheburash
Posts: 5
Joined: 15. Jul 2016, 03:40

Re: linking error for Bstr

Post by cheburash »

I see, then it would be nice to mention in the guide which functionality is not implemented yet.

I just would like o use basic functions like
find VM by name, clone VMs, restore snapshots, start and stop VMs.

I think I've discovered that even for this kind of functionality I need to refer to Virtual Box source tree,
I don't remember exactly for what, but can dig it up again.

Thanks
klaus
Oracle Corporation
Posts: 1133
Joined: 10. May 2007, 14:57

Re: linking error for Bstr

Post by klaus »

Would be very helpful if you could let us know why the SDK isn't enough without referring to the VirtualBox sources. Must be a misunderstanding and it's best to sort out such issues early (maybe with a documentation change, in addition to the Bstr hiccup). I know that the entire API can be used purely with the SDK, because there are several customers doing this.
Post Reply