5

I wanted to download the lame library for use in my C# project to convert audio. I found the files to use here (libmp3lame)

When I downloaded the archive, I found the .dll I was looking for but along with them, there were 2 others files:

  • libmp3lame.dll
  • libmp3lame.exp
  • libmp3lame.lib

My question:

  1. 1 What are these files used for? And how can I make use of them in my project apart from the .dll file
  2. What benefit do these files give me that the .dll library cant?

Edit: I have a feeling that these files are not for use in C#. More for C++. But either way, what are those files? And what are they used for?

Community
  • 1
  • 1
Krimson
  • 7,386
  • 11
  • 60
  • 97
  • I believe those are for when you are compiling with C++. Don't think C# can even use *exp* or *lib* files (never tried though). – TyCobb Dec 03 '14 at 18:13
  • @TyCobb Yea, I had a feeling that it wont work with c# but still, what are those files used for? – Krimson Dec 03 '14 at 18:14
  • 1
    http://msdn.microsoft.com/en-us/library/se8y7dcs.aspx | http://stackoverflow.com/questions/2727020/what-is-use-of-exp-and-what-is-the-difference-between-lib-and-dll – TyCobb Dec 03 '14 at 18:18
  • They are meant for other C/C++ projects to use the DLL. You have no use for them in a C# project. A C++/CLI project can however use them, the other .NET way to run native code. – Hans Passant Dec 03 '14 at 18:34

2 Answers2

5

Both lib files and exp files are used with native code development (e.g. C++/VB6/Win32) and are not used at all in the .NET world.

lib files contain a collection of reusable code or data or both that can be statically linked and reused with your existing code. They are similar to DLL files, except the big difference being DLL files are linked dynamically and LIB files are linked statically, when you compile your program.

exp files are export files. There are kind of like metadata files that tell your compiler which functions in a DLL have been exported, and therefore can be reused in your statically linked program. .NET program do not require this because each .NET DLL has a special section called the CLR Metadata section. .NET programs can use reflection to pull this metadata information and see which methods are available.

Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • Sometimes `.lib` contains actual code and data, sometimes it's just an import library (and it also can be both). – Ben Voigt Dec 03 '14 at 18:25
  • Is it possible to bundle the `.lib` and `.exp` inside the `.dll` file? I am developing a c# program based on a template from the web. The build process generates those extra files. If I use the '.dll' file alone (as a plugin for some program), I get error about encoding, but if I put the 3 files together on same directory, the plugin works fine. So, is it possible to merge them into the `.dll` file? Thanks. – W.M. Sep 01 '16 at 11:04
  • 1
    @W.M. - The `.lib` and `.exp` files are used during development. They shouldn't be needed when you distribute your application. If you do not need them, then you can create a post build rule in Visual Studio, such as `del $(OutDir)\$(ProjectName).lib`. – Icemanind Sep 06 '16 at 22:57
0

If you think about the method for consuming a native DLL in .NET (p/invoke), your p/invoke declarations have several parts:

  • The function signature (return time, argument types)
  • DllImportAttribute specifying the DLL where the function is found and its key in the export table (mangled name or ordinal)

In C and C++, the header file provides the first, and the import library, ending in .lib, provides the second.

Unlike p/invoke's DllImportAttribute, in C and C++ the calling convention is stored with the function signature in the header file.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720