zyantific / zydis

Fast and lightweight x86/x86-64 disassembler and code generation library
https://zydis.re
MIT License
3.4k stars 434 forks source link

LNK2001 static linking #370

Closed RadonCoding closed 2 years ago

RadonCoding commented 2 years ago

I built the repository using CMake and included it in my project. When trying to build i get the following errors error LNK2001: unresolved external symbol __imp_ZydisDecoderInit error LNK2001: unresolved external symbol __imp_ZydisDecoderDecodeFull

This is my directory setup:

C:.
└───zydis
    ├───include
    │   ├───Zycore
    │   │   ├───API
    │   │   └───Internal
    │   └───Zydis
    │       ├───Generated
    │       └───Internal
    ├───lib
    └───src
        ├───Zycore
        │   └───API
        └───Zydis
            └───Generated

Here are my project settings:

Additional Include Directories: $(SolutionDir)Dependencies\zydis\include
Additional Library Directories: $(SolutionDir)Dependencies\zydis\lib
Additional Dependencies: Zycore.lib;Zydis.lib;
flobernd commented 2 years ago

@RadonCoding Could you please try to set ZYDIS_STATIC_BUILD in the compiler commandline flags? ZYCORE_STATIC_BUILD might be required as well if you plan to use any of the Zycore exports (Zydis itself only uses Zycore header files).

The _imp_ prefix is used when the API is exported using declspec(dllexport). CMake takes care of not using it when ZYDIS_STATIC_BUILD is defined. If your project does not define this macro as well, declspec(dllimport) is used for an export that is not marked as declspec(dllexport) and causes the linker error.

RadonCoding commented 2 years ago

Sorry where do i set the compiler commandline flags?

flobernd commented 2 years ago

You can use -D ZYDIS_STATIC_BUILD in the command line or set it in the project options in Visual Studio like this:

RadonCoding commented 2 years ago

Thanks for the fast response. That worked!