0

I have a VS2022 C++ project that uses zstd. Previously, it used zstd v1.5.2; I changed this to v1.5.6 (the current version). Now when I attempt to run the project, I get an error "The code execution cannot proceed because zstd.dll was not found".

So, apparently, the linker has assumed zstd should be used in a dynamic library, but I want to use it in a static library. I have the static library zstd.lib from the official release, and I want to force the linker to use it, rather than the dll.

I've created a small test project that illustrates the issue. Here is the code:

#include <iostream>
#define ZSTD_STATIC_LINKING_ONLY
#undef ZSTD_DLL_EXPORT
#include "zstd.h"

int main()
{
    const char *pVn = ZSTD_versionString();
    std::cout << "zstd version is " << pVn << "\n";
    char src[] = { "This is some test data to be compressed, preferably by a large factor, using zstd in a static library" };
    char dst[1000];
    size_t compressedSize = ZSTD_compress(dst, 1000,
        src, strlen(src),
        ZSTD_CLEVEL_DEFAULT);
}

This project is being linked with linker options

General / Additional Library Directories C:\Miscellaneous_Libraries\zstd-dev\zstd-1.5.6;%(AdditionalLibraryDirectories)
and
Input / Additional Dependencies zstd.lib;%(AdditionalDependencies)
The entire linker command line is
   /OUT:"C:\Miscellaneous_Libraries\zstd-dev\zstd-1.5.6\zstd_static\x64\Debug\zstd_static.exe" /MANIFEST /NXCOMPAT
   /PDB:"C:\Miscellaneous_Libraries\zstd-dev\zstd-1.5.6\zstd_static\x64\Debug\zstd_static.pdb"
   /DYNAMICBASE "zstd.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib"
         "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib"
         "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X64 /INCREMENTAL 
  /PGD:"C:\Miscellaneous_Libraries\zstd-dev\zstd-1.5.6\zstd_static\x64\Debug\zstd_static.pgd"
   /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'"
     /ManifestFile:"x64\Debug\zstd_static.exe.intermediate.manifest" /LTCGOUT:"x64\Debug\zstd_static.iobj"
  /ERRORREPORT:PROMPT /ILK:"x64\Debug\zstd_static.ilk" /NOLOGO
 /LIBPATH:"C:\Miscellaneous_Libraries\zstd-dev\zstd-1.5.6" /TLBID:1 

How can I prevent the linker from making the excutable attempt to load zstd.dll?

VS2022 17.6.5; C++20; windows 11 Pro 64-bit

3
  • Are you sure zstd.lib is the correct file? Just peeked inside the official release at github.com/facebook/zstd/releases/download/v1.5.6/… and there is no such file; there is libzstd_static.lib instead. Commented Oct 18, 2024 at 22:06
  • I think zstd.lib was built by vcpkg (the Windows package manager), but it is indeed a static library, per dumpbin. In any case, the error is "missing dll", so apparently the static library is being ignored. Commented Oct 20, 2024 at 7:17
  • I have upgraded zstd to v1.5.7 and managed (somehow) to prevent building with the libzstd_static.lib. Now I have another problem: I am getting messages like the following: LINK : warning LNK4217: symbol 'calloc' defined in 'libucrtd.lib(calloc.obj)' is imported by 'libzstd_static.lib(zstd_decompress.obj)' in function 'ZSTD_customCalloc' This apparently is occurring because the VS2022 C++ C runtime library libucrtd.lib contains calloc, and so does libzstd_static.lib. How do I fix this? Commented Mar 24 at 4:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.