Managed C++ calling unmanaged C++ DLL - unresolved external symbol error

G

guxu

I have a managed C++ code which calls some methods in unmanaged C++
DLL.
In my unmanaged DLL, I have a PROTECTED virutal function in a base
class and derived class has a PRIVATE function which overrides the
virutal one in the base.
In my managed class, I have the following

private:
CUnmanaged __nogc* m_pUnManaged

constructor
ManagedApiWrapper::ManagedApiWrapper()
{
m_pUnManaged = new CUnmanaged();
}

void ManagedApiWrapper::managed_helloworld(String *msg)
{
m_pUnManaged-><func_a>;
}

The <func_a> is from the derived class in that unmanaged DLL. I got
compiler error complaining on unresolved external symbol of that
protected virtual function in base class. The error will be gone if I
remove the <virtual> from the base class function.

What could be causing the error?
Thanks.
 
C

Carl Daniel [VC++ MVP]

I have a managed C++ code which calls some methods in unmanaged C++
DLL.
In my unmanaged DLL, I have a PROTECTED virutal function in a base
class and derived class has a PRIVATE function which overrides the
virutal one in the base.
In my managed class, I have the following

private:
CUnmanaged __nogc* m_pUnManaged

constructor
ManagedApiWrapper::ManagedApiWrapper()
{
m_pUnManaged = new CUnmanaged();
}

void ManagedApiWrapper::managed_helloworld(String *msg)
{
m_pUnManaged-><func_a>;
}

The <func_a> is from the derived class in that unmanaged DLL. I got
compiler error complaining on unresolved external symbol of that
protected virtual function in base class. The error will be gone if I
remove the <virtual> from the base class function.

What could be causing the error?

Something doesn't' quite add up. "Unresolved external" is a linker error,
not a compiler error. So which is happening:

1. You get a linker error when building your managed DLL?
2. You get a linker error when building your unmanaged DLL?
3. You get a compiler error when building your managed DLL? In this case,
what's the exact error message?

Are any of the relevant functions of the unmanaged classes defined as inlie
(e.g. function body in the class definition)?

Which compiler are you using (7.0, 7;.1, 8.0)?

-cd
 
G

guxu

Sorry for the confusion. They were linker errors, not compiler errors.
I do not get any errors with UNmanaged DLL. I am getting Linker error
when building managed DLL complaining the protected virutal function in
the base class. The overriding function in the derived class is a
private function.

The unmanaged DLL 's base class does have some inline functions.

I am using C++ .NET, compiler 7.1.

Thanks.
 
C

Carl Daniel [VC++ MVP]

Sorry for the confusion. They were linker errors, not compiler errors.
I do not get any errors with UNmanaged DLL. I am getting Linker error
when building managed DLL complaining the protected virutal function
in
the base class. The overriding function in the derived class is a
private function.

The unmanaged DLL 's base class does have some inline functions.

I am using C++ .NET, compiler 7.1.

OK. Is the overriding function on the derived class inline? If it is, try
making it out of line. Is the constructor or destructor for the either
class (base or derived) inline? If it is, trying making them out of line.
Is the base class defined in a single header file, or is the definition
duplicated in two or more places? If the latter, make sure that the class
definitions are identical (or better yet, arrange for the definition to
appear in a single location).

-cd
 
G

guxu

Thanks for help.

But the overriding function in the derived class is NOT inline. The
constructors and destructors in both base and derived classes are NOT
inline. The base class is defined in ONE header file.

Some of the functions in the derived class do call those inline
functions in the base class, but not the one being complained by the
linker.

What else could possibly cause this error?
Thanks.
 
C

Carl Daniel [VC++ MVP]

Thanks for help.

But the overriding function in the derived class is NOT inline. The
constructors and destructors in both base and derived classes are NOT
inline. The base class is defined in ONE header file.

Some of the functions in the derived class do call those inline
functions in the base class, but not the one being complained by the
linker.

What else could possibly cause this error?

Hmmm. A good question! I'm trying to think of reasons why the managed DLL
would try to reference the name of the virtual function defined in the base
class, and I'm just about out of ideas.

I think the next thing I'd try is using dumpbin /symbols on all the .OBJ
files that go into the Managed DLL and find out which one is referencing the
problematic symbol, then work backwards from there to figure out what in the
source code is causing that reference.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top