LNK4089 and more :)

Hi!

I have a DLL (FWFCR.dll) which links with:
obr.lib
forostubsr.lib
nsldapssl32v30.lib
ws2_32.lib

I have a EXE which links with:
FWFCR.lib
forostubsr.lib
obr.lib

Several things:

1.- In my exe, I get this warning LNK4089: all references to "OBR.dll" discarded by /OPT:REF

But if I remove obr.lib in link setting, I get unresolved external symbols.

2.- If my DLL is linked with obr.lib and with forostubsr.lib, why do I need to include them in my EXE? If I don't include them, I get errors.

Thank you in advance.
[613 byte] By [irona20] at [2007-11-18 1:40:16]
# 1 Re: LNK4089 and more :)
This warning simply means that you are linking against a library and the linker has detected that you are not really using any functions from it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcce/htm/errlink_172.asp

You can also use the /IGNORE:4089 in the linker settings.
Mick at 2007-11-10 8:54:12 >
# 2 Re: LNK4089 and more :)
Originally posted by Mick_2002
This warning simply means that you are linking against a library and the linker has detected that you are not really using any functions from it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcce/htm/errlink_172.asp

You can also use the /IGNORE:4089 in the linker settings.

Yes, I know that... but my real question was:

In my exe, I get this warning LNK4089: all references to "OBR.dll" discarded by /OPT:REF

But if I remove obr.lib in link setting, I get unresolved external symbols

So, if I don't need that library, because if I remove it, my app doesn't link :) :D

PS: And there is a second question in this thread :)
irona20 at 2007-11-10 8:55:12 >
# 3 Re: LNK4089 and more :)
Yes but ;)
Other occurences of this warning can occur if an unused function in your code references a .dll export that the linker has discarded.

What are your link errors are you really using the calls?
Mick at 2007-11-10 8:56:09 >
# 4 Re: LNK4089 and more :)
Other occurences of this warning can occur if an unused function in your code references a .dll export that the linker has discarded.

But in my EXE there is only a function calling a my .dll export.

Anyway, I would like my second question was answered, because I don't want to include my two libraries (obr.lib and forostubsr.lib) in my EXE.
irona20 at 2007-11-10 8:57:14 >
# 5 Re: LNK4089 and more :)
Other occurences of this warning can occur if an unused function in your code references a .dll export that the linker has discarded.

But in my EXE there is only a function calling a my .dll export.
(I don't know if you mean that, but with /VERBOSE there are too information :D )

Anyway, I would like my second question was answered, because I don't want to include my two libraries (obr.lib and forostubsr.lib) in my EXE.

Thank you!! :D
irona20 at 2007-11-10 8:58:12 >
# 6 Re: LNK4089 and more :)
Originally posted by irona20
Anyway, I would like my second question was answered, because I don't want to include my two libraries (obr.lib and forostubsr.lib) in my EXE.

Thank you!! :D
Well...usually this could happen due to '#include' statements or functions call to these libraries inside your dll header which will be included into your application.

For example:

// dll.h
#include <obr.h>

...

void mydllfunc()
{
obrfunctioncall();
}

// app.h
#include <dll.h>

In this case the compiler needs to know both header file ('obr.h') and the library ('obr.lib') to actually be able to compile the application.

There is a so-called 'pImpl' pattern which basically looks like the following...

class CDllImpl; // Forward declaration of implementation class

class CDll
{
public:
void Function();
// all your functions etc.

private:
CDllImpl *m_pImpl;
};

// dll.cpp
#include <dll.hpp>
#include <dllimpl.hpp>

CDll::CDll()
{
m_pImpl = new CDllImpl;
}

CDll::~CDll()
{
delete m_pImpl;
}

void CDll::Function()
{
m_pImpl->Function();
}

// dllimpl.hpp
#include <SomeHeader>; // Here you can put all your needed headers

class CDllImpl
{
public:
void Function();
...
};

// dllimpl.cpp
void CDllImpl::Function()
{
// Do some processing
}

So, with this you only need to distribute the header 'dll.hpp', import library and the dll. 'dll.hpp' acts like an interface (wrapper) to your dll. The whole functionality will be inside the implementation class.
Andreas Masur at 2007-11-10 8:59:11 >
# 7 Re: LNK4089 and more :)
Just as an aside to all the other stuff. When you run into errors sometimes it helps to do rebuild all to be sure it isn't VC++ just acting flaky. I have run into this too many times to remember. If after rebuild all still does the same then you are sure it is more what Andreas states.
antares686 at 2007-11-10 9:00:12 >
# 8 Re: LNK4089 and more :)
Originally posted by Andreas Masur

Well...usually this could happen due to '#include' statements or functions call to these libraries inside your dll header which will be included into your application.

For example:

// dll.h
#include <obr.h>

...

void mydllfunc()
{
obrfunctioncall();
}

// app.h
#include <dll.h>

In this case the compiler needs to know both header file ('obr.h') and the library ('obr.lib') to actually be able to compile the application.

There is a so-called 'pImpl' pattern which basically looks like the following...

class CDllImpl; // Forward declaration of implementation class

class CDll
{
public:
void Function();
// all your functions etc.

private:
CDllImpl *m_pImpl;
};

// dll.cpp
#include <dll.hpp>
#include <dllimpl.hpp>

CDll::CDll()
{
m_pImpl = new CDllImpl;
}

CDll::~CDll()
{
delete m_pImpl;
}

void CDll::Function()
{
m_pImpl->Function();
}

// dllimpl.hpp
#include <SomeHeader>; // Here you can put all your needed headers

class CDllImpl
{
public:
void Function();
...
};

// dllimpl.cpp
void CDllImpl::Function()
{
// Do some processing
}

So, with this you only need to distribute the header 'dll.hpp', import library and the dll. 'dll.hpp' acts like an interface (wrapper) to your dll. The whole functionality will be inside the implementation class.

Like always you're right!!!
But I am afraid that I cannot use your solution because in my DLL's headers I use a lot of structures&classes&defines& etc defined in my obr.lib :(
But thank you very much!!!
irona20 at 2007-11-10 9:01:15 >
# 9 Re: LNK4089 and more :)
Originally posted by irona20
But I am afraid that I cannot use your solution because in my DLL's headers I use a lot of structures&classes&defines& etc defined in my obr.lib :(
But thank you very much!!!
Well...do you use the structures etc. only in your dll header file? Or do you need them in your application as well? If the former one there chances might be high that they can be hidden to the application either with the solution described above or forward declarations etc.

If it is the latter one (which I assume from your words) then of course it is not possible...
Andreas Masur at 2007-11-10 9:02:22 >
# 10 Re: LNK4089 and more :)
Originally posted by Andreas Masur

Well...do you use the structures etc. only in your dll header file? Or do you need them in your application as well? If the former one there chances might be high that they can be hidden to the application either with the solution described above or forward declarations etc.

If it is the latter one (which I assume from your words) then of course it is not possible...

No, in my app aren't used.
An example:

// Process.h: interface for the CProcess class.
//
//////////////////////////////////////////////////////////////////////
#include <OB/CORBA.h>
#include "factory.h"

class __declspec(dllexport) CProcess
{
public:
CProcess (FORO_ProcessModel_var pForoProcessModelInfo, bool bIsStartable,
CEngine* pEngine);
CProcess(FORO_ProcessModel_var pForoProcessModelInfo, CEngine* pEngine);
private:
FORO_ProcessModel_var m_pForoProcessModel;

private:
FORO_ProcessModel_var GetProcessModel();

};

obr.lib & forostubsd is necessary for:
FORO_ProcessModel_var

#include <OB/CORBA.h>
#include "factory.h"

And in my exe, I include my process.h.
irona20 at 2007-11-10 9:03:22 >