Link to home
Start Free TrialLog in
Avatar of kalyan67
kalyan67

asked on

undefined reference to FILENAME

Hi,
I am building a small program in C, which will link to a dll during runtime. But during development process since I cannot use dll file I have included a .LIB file supplied by the vendor. The definitions of the functions( in the dll) are present in .h file and I am including that.
But when I try to call one of those functions and when I compile that I am getting the following error:
[Linker Error] undefined refernce to 'FUNCTION_NAME'.

I am using Dev C++ compiler.

Can anyone help me.

kalyan
Avatar of Axter
Axter
Flag of United States of America image

Hi kalyan67,
Exactly what is your question?

David Maisonave (Axter)
Cheers!
You don't only need a .lib file for the functions imported from the DLL, you also need a header file (.h) where these functions are declared, so the compiler "knows" them. The header file you need should ship with the same package as the .lib file, just add

#include <thefilesname.h>

to your code.
Avatar of grg99
grg99

You have to pass the .lib file name to the linker, probably with a -l option.

Avatar of kalyan67

ASKER

Thanks for the replies
Hi Axter,
My question is what does
[Linker error] Undefined reference to 'FUNCTION_NAME'  means and I am trying to solve it.

and Hi jkr,
I have included the header file and  it is recognizing that (otherwise I would get the error FUNCTION_NAME undeclared).
But still I am getting the linker error.


Kalyan
Wait a minute - the linker does not complain about not finding the .lib. Then it could also be a name mangling problem. You could try

extern "C" {
#include <thefilesname.h>
}
Yes I have inculed the .lib file in options and  linker is not complaining about .lib file.

Hi Jkr,
Ive tried using extern "C" and  extern"C++" still no use.

kalyan
Maybe the .lib file format is not compatible. Does the vendor explicitly support Dev C++?
Hi Jkr,
Thanks for the quick replies.
The vendor doesnot explicitly support DEV C++ ,
I am trying to do with other compliers, ive just installed CYGWIN.
To be sure is this the command to compile in gcc?

(FEUSB.LIB is the Library)
gcc -lFEUSB USB_SCAN.cpp

kalyan
Actually, when you specify it like that, it will be expanded to 'libFEUSB.a', according to the library naming scheme. But, since there is not 'file not found' message, I assume that is not the problem. Just to be sure, the .lib is in the same directory as the source code file?
I recommend you convert the FEUSB.LIB to a FEUSB.a file.

There are free conversion tools available for this.
sorry for my ignorance, but can you recommend some tools, I cannot find anything online
kalyan
To make a *.a file I used the dlltool which comes Dev-C++.  Actually, it probably comes with the GNU compiler, but I haven't verified that yet.
ASKER CERTIFIED SOLUTION
Avatar of Axter
Axter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Axter, for ur help, ive created .o file it solved my problem.

Thanks JKR for ur help

kalyan