0

I have no experience with Windows, just Linux. I'm trying to compile a project that comes as a Visual Studio project. Simply opening the project and building goes ok, but when I run, Windows tells me that it couldn't find some .dll that comes with the project but are outside the Visual Studio project folder. It also comes with .lib files with the same name.

Should I link these lib files in the build process? I guess no, because if I should do this, then it would be included in the Visual Studio Project already.

Can I install them then? Or can I instruct my executable where to find them when I run?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • Impot the library using `#pragma comment(lib,"libname")` somewhere in your source, then call the functions which are exported in the lib. If they're in a dll, then linking the lib will load the dll automatically and you'll still need to call the exported functions – Irelia Feb 14 '20 at 00:53
  • @Nina now that you gave the idea, I noted that indeed there is a code that imports these `.lib` files: `WPMainCore.lib, CTMedia.lib, CTStream.lib`. However, when I run the executable, I get errors saying that `CTStream.DLL`, for example, couldn't be found. Why it uses the `.lib` but complains about `dll` when I run? – Guerlando OCs Feb 14 '20 at 00:56
  • https://stackoverflow.com/questions/1776060/how-to-make-visual-studio-copy-a-dll-file-to-the-output-directory – Hans Passant Feb 14 '20 at 00:58
  • @HansPassant thanks. But if I'm building with `x.lib`, why Windows complains that `x.dll` couldn't be found when I run the program? Shouldn't `x.lib` already implement things? – Guerlando OCs Feb 14 '20 at 00:59
  • 2
    x.lib is the *import library* for x.dll. It merely lists the exported functions, it doesn't contain any code. The code lives in the dll. – Hans Passant Feb 14 '20 at 01:02
  • @HansPassant before commenting here I searched for "dll vs lib" and they said it was just like `.a` and `.so`, but apparently it isn't. Because when I link a `.a` I don't need to provide the `.so`. But shouldn't the `.h` file list the exported functions? Why a `.lib` is needed? – Guerlando OCs Feb 14 '20 at 01:29
  • @guerlando if you have access to CTStream.dll then just put it in the directory of the executable. If you're compiling CTStream yourself and you want to link only the libs and not need the dll, then compile the project as /MT in your VS linker settings. I'm not sure how you got the lib files with no dll – Irelia Feb 14 '20 at 01:31
  • 1
    There are two kind of .lib files. Static libraries are like .a, they contain the code and the linker links it into the main executable. No .dll is needed. But an import library is just a list of the functions that are exported by a .dll. The linker needs it to know where the function lives and uses it to create the import table in the executable. It is primarily necessary because an exported function in a .dll doesn't have to have a name. That these files have the same filename extension was an unfortunate choice. – Hans Passant Feb 14 '20 at 02:18
  • I suggest you could refer to the Doc: [Walkthrough: Create and use your own Dynamic Link Library](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019) – Jeaninez - MSFT Feb 14 '20 at 02:56

0 Answers0