3

I have a C++ project that output a C++ .exe . The project is dependant of some .lib and .dll. If I want to use the .exe on another server, can I just transfer the .exe withtout the .lib, .dll, and .obj? Do the .exe was build so it 'includes' these files?

Thank you!

  • You can't copy the executable without them and see if it works to figure this out? – Ken White Sep 26 '18 at 00:55
  • 1
    If we are talking about Visual Studio, then your program will have the Visual C++ Redistributable equivalent to the Visual Studio version you are using as dependency. You are not supposed to copy the .DLLs, but install Visual C++ Redist on the target machine instead. – Havenard Sep 26 '18 at 01:39
  • Ken White: yes but I wanted to understand how it works. – Gabriel Beauchemin-Dauphinais Sep 26 '18 at 18:42

1 Answers1

2

The compile/link process in C++ is complex but generally follows this path.

cpp/hpp-> obj

obj -> lib (.a) for a static library or obj -> dll (.so) for a dynamic library

obj, lib, dll -> exe

The link process will take obj and static libs and form a self contained exe. The linker makes the exe depend on dlls but the exe will not contain the dynamic library.

Answering your questions, the exe and dll(s) will be needed at runtime. The obj and static lib files will definitely not be needed at runtime.

Matthew Fisher
  • 2,258
  • 2
  • 14
  • 23
  • 1
    However ... Do *not* simply determine which DLLs your program depends on, and blindly copy those to the other machine. It *might* work, but it very likely will not as there may be other dependencies or configuration that is missing. – Steve Sep 26 '18 at 01:36
  • 1
    Unless you created those DLLs yourself or know they are easily portable in that fashion. – Steve Sep 26 '18 at 01:37
  • 1
    Please consider @Steve important comment before proceeding. Copying system dlls is not advised for example – Matthew Fisher Sep 26 '18 at 01:41