How can I get rid of the __imp__ prefix in the linker in VC++?

后端 未结 5 1203
野性不改
野性不改 2020-12-01 06:29

I\'m using libcurl and am getting the following sort of linker errors in VC++ 10.

1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_         


        
相关标签:
5条回答
  • 2020-12-01 06:33

    The __imp__ prefix appears whenever you are linking to a DLL. It does not appear when linking to statically linked libraries. Most likely the code is generated to be linked against a DLL import lib, but you have linked it with a static lib instead.

    The prefix is added when you mark the imported function with __declspec(dllimport) - make sure your imports are not using this when not linking against a DLL.

    0 讨论(0)
  • 2020-12-01 06:40

    You have to add CURL_STATICLIB to Preprocessor Definitions at the properties of your projects in MSVC

    0 讨论(0)
  • 2020-12-01 06:41

    If using wizard generated projects - check "Runtime settings" value in project properties -> C/C++ -> Code Generation section.

    By default it usually has "Multithreaded DLL" value. You need Multithreaded /MT and Multithreaded Debug /MTd values.

    0 讨论(0)
  • 2020-12-01 06:48

    You are using a header file that defines the function prototype with the specifier evaluating to __declspec(dllimport)

    You need to either redefine the statement that is evaluating to this (set it to nothing), or use a different header file altogether.

    Typically you'll see code like this:

    #ifdef FOO_EXPORTS
    #define DLLSPEC __declspec(dllexport)
    #else
    #define DLLSPEC __declspec(dllimport)
    #endif
    
    ...
    
    DLLSPEC bool foo(int bar);
    

    Compiling the project with FOO_EXPORTS defined will use one mode and without it will use the other.

    0 讨论(0)
  • 2020-12-01 06:59

    As Suma mentioned, <your_library>.dll is normally accompanied by <your_library>.lib. Therefore if you get such error messages like

    Error LNK2019 unresolved external symbol __imp__<your_symbol> referenced in function ...

    it is highly recommended to check the Linker settings of your project.

    In Visual Studio, just go for your project to

    Properties -> Linker -> General
    

    and check under entry Additional Library Directories, if the path to <your_library>.lib is defined there. If not, just add it.

    Then check and define on

    Properties -> Linker -> Input
    

    under entry Additional Dependencies the probable missing <your_library>.lib.

    The error message should disappear now.

    Hope it helps?

    0 讨论(0)
提交回复
热议问题