tags:

views:

549

answers:

2

I have downloaded a library for the purposes of writing a program that can uncompress a RAR file. (http://www.rarlab.com/rar/UnRARDLL.exe) This supplies me with unrar.dll, unrar.h, unrar.lib and UnRDLL.def. I have copied the C example code and have tried compiling it with both Dev-Cpp and Eclipse.

I don't have much experience using DLLs, so I don't know how to deal with the following linker errors:

UnRDLL.o(.text+0x151):UnRDLL.c: undefined reference to RAROpenArchiveEx@4' UnRDLL.o(.text+0x1c0):UnRDLL.c: undefined reference to RARSetCallback@12' UnRDLL.o(.text+0x1e2):UnRDLL.c: undefined reference to RARReadHeader@8' UnRDLL.o(.text+0x2b9):UnRDLL.c: undefined reference to RARProcessFile@16' UnRDLL.o(.text+0x2fe):UnRDLL.c: undefined reference to RARCloseArchive@4' UnRDLL.o(.text+0x366):UnRDLL.c: undefined reference to RAROpenArchiveEx@4' UnRDLL.o(.text+0x3d6):UnRDLL.c: undefined reference to RARSetCallback@12' UnRDLL.o(.text+0x41c):UnRDLL.c: undefined reference to RARReadHeaderEx@8' UnRDLL.o(.text+0x4c2):UnRDLL.c: undefined reference to RARProcessFile@16' UnRDLL.o(.text+0x4fa):UnRDLL.c: undefined reference to RARCloseArchive@4'

Google suggested adding --def UnRDLL.def and -lunrar to the linker options and also copying the .lib file to the Dev-Cpp\lib directory.

Can you please explain to me what I'm doing wrong? If possible, tell me what files need to be in the source code directory, what needs to be with libraries, what needs to be added to the project and what linker options there need to be, as well as anything else I've totally missed.

EDIT: I don't know why, but I just manually redid all the settings as described above and now it works. Thanks for your help anyway.

+2  A: 

I recommend using Visual Studio Express (freely available from Microsoft at the provided link) to compile and link your program. I think it's a bit simpler in this instance than the other tools that you mentioned, although that's just my personal opinion.

I recommend using a layout similar to this for your project:

\myproject
  \src
  \include
\thirdparty
  \bin
  \lib
  \include

Your C/C++ source files will live under myproject\src and your header files will live under myproject\include. The library files that you downloaded live under thirdparty: the DLL belongs in bin, the .lib file and .def file belong in lib, and the library's header files belong in include.

Next, you need to configure your project in Visual Studio Express. In your project properties, under Linker -> General, add \thirdparty\lib to Additional Library Directories. Under Linker -> Input, add unrar.lib to Additional Dependencies. This tells Visual Studio Express the name and location of your thirdparty library, so that it can link it into your main application.

When running your program, you'll need to copy unrar.dll to your project's output directory so your program can load it.

This should help you to get going...

Emerick Rogul
I've used VSE before and I prefer Eclipse (or DevCpp for smaller projects). I know it's often easier to use DLLs with VSE, but I'd prefer to learn how to use them with other IDEs.
thornate
Fair enough. I played around with Eclipse and DLLs before, but I just found it too frustrating, personally. This is one specific case where using the "vendor-supplied" tool-chain really helps productivity, IMO.
Emerick Rogul
A: 

Back in the day, Borland used to supply a tool for creating a lib file from a def file.

In the modern world, your best bet is to add the lib file to your project under Project->Properties Config Props->Linker->Input->Additional Dependancies. You may need to add the lib file location to Props->Linker->General->Additional Lib Dirs. Make sure the DLL is on your path or copied in with the executables.

Simon Featherstone
Which IDE are you referring to?
thornate
VC2005. VC2008 will be very similar.
Simon Featherstone