包含静态库的头给dllimport错误

问题描述:

我有后来使用Xerces-c,它可以构建为静态或动态库提供的代码。如果不包括在编译器错误路线的结果,但是当我添加#include <xercesc/util/PlatformUtils.hpp>的Visual Studio 2012给了我一个链接错误,他说:包含静态库的头给dllimport错误

1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Initialize(char const * const,char const * const,class xercesc_3_1::PanicHandler * const,class xercesc_3_1::MemoryManager * const)" ([email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function _main 
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Terminate(void)" ([email protected]@[email protected]@SAXXZ) referenced in function __catch$_main$0 
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char const * const xercesc_3_1::XMLUni::fgXercescDefaultLocale" ([email protected]@[email protected]@2QBDB) 

基于错误的dllimport部分似乎它没有找到一个dll 。当我将Xerces-c构建为动态库并链接到它时,错误就消失了。但是,如果我将Xerces-c构建为静态库并链接到它,仍然会出现相同的错误。所以我的问题是为什么当我包含并链接到一个静态库时,我得到一个错误,要求一个DLL?

using namespace xercesc; 
int main(int argc, char* argv[]) 
{ 
    std::ifstream inputFile(argv[1]); 
    char c = inputFile.get(); 

    while (inputFile.good()) { 
    std::cout << c; 
    c = inputFile.get(); 
    } 

    try { 
    XMLPlatformUtils::Initialize(); 
    } 
    catch (const XMLException& toCatch) { 
    // Do your failure processing here 
    return 1; 
    } 

    // Do your actual work with Xerces-C++ here. 
    //XercesDOMParser parser; 
    //parser.useScanner(XMLUni::fgDGXMLScanner); 


    XMLPlatformUtils::Terminate(); 

    // Other terminations and cleanup. 
    return 0; 
} 

您需要XERCES_STATIC_LIBRARY预处理宏编译您的应用程序禁用的Xerces库DLL导入/导出。

此外,请检查您是否与静态版本的.lib文件链接。