c++ - 在 VS17 上链接库失败并显示 LINK1181

标签 c++ visual-studio-2017 libraries visual-studio-2017-build-tools adtf

我正在尝试在我的项目中使用 ADTF 流媒体库。当我包含库时,出现 LNK1181 错误。该库附带 header 、lib 文件和 dll 文件。

我在 C/C++ -> General -> Additional Include Directories 中添加了路径。

enter image description here

另外,我在 Linker -> Input -> Additional Dependencies 添加了库。

enter image description here

这里也是错误截图。

enter image description here

更新:我已将 dll 和库的位置更改为我的项目路径并再次包含它。它现在不提示 lib 本身。现在我收到错误 LNK2001。我相信这也是一个链接器错误。

enter image description here

这里哪里出了问题!

enter image description here

更新 2: 在我看到构建的完整日志之后。这出现,我认为这意味着,链接器找不到我的库。是吗?

enter image description here

主要应用代码如下:

#include "pch.h"
#include <iostream>
#include "adtf_streaming.h"
using namespace adtfstreaming;

int main()
{
    std::cout << "Hello World!\n"; 
    IADTFFileReader *pFileReader = IADTFFileReader::Create();

}

试图读取/导入我的库的头文件是

#ifndef _ADTF_STREAMING_LIBRARY_DLL_ 
#define _ADTF_STREAMING_LIBRARY_DLL_

#ifdef WIN32
    #ifdef STREAMINGLIB_EXPORTS
        #pragma message ("Create ADTF Streaming Library ")
        // export symbols
        #define DOEXPORT __declspec( dllexport )
    #else
        #pragma message ("Use dynamic ADTF Streaming Library ")
        #ifdef _DEBUG
            #pragma comment( lib, "adtfstreamingD_290.lib" )
        #else
            #pragma comment( lib, "adtfstreaming_290.lib" )
        #endif

        #define DOEXPORT __declspec( dllimport )
    #endif
#else
    #ifdef STREAMINGLIB_EXPORTS
        #define DOEXPORT __attribute__ ((visibility("default")))
    #else
        #pragma comment( lib, "adtfstreaming_290.lib" )
        #define DOEXPORT __declspec( dllimport )
    #endif
#endif

//standard includes 
#include <stdlib.h>
#include <string.h>

//adtf base types and errors
#include "adtf_base_ref.h"

//streaming lib version
#include "adtf_streaming_version.h"

//adtf streaming lib package headers
#include "adtf_streaming_pkg.h"

#endif //_ADTF_STREAMING_LIBRARY_DLL_

最佳答案

您需要在链接器属性中指定附加库目录,以设置您拥有 lib 文件的目录。您不需要将库包含在附加依赖项中,因为当您在调试或 中编译您的应用程序时,您是在 lib 头文件code>#pragma comment( lib, "adtfstreaming_290.lib") 在发布时编译。但是您需要在其他库目录中指定这些库的位置。

如果您查看 lib 包含文件,您会发现如果定义了 STREAMINGLIB_EXPORTS 宏,则所有带有 DOEXPORT 修饰符的函数都是导出函数 #define DOEXPORT __declspec( dllexport )。但是如果这个宏没有定义#define DOEXPORT __declspec( dllimport ),同样的函数是导入函数。是因为dll需要指定这个函数是导出函数,所以在dll代码中有人定义了这个宏。因为在你的代码中你没有(你不能)定义这个宏,这个函数是导入函数。

关于c++ - 在 VS17 上链接库失败并显示 LINK1181,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58605032/

相关文章:

c++ - 如何在给定 ActiveX 控件的 HWND 的情况下获得 COM 接口(interface)?

c# - Xamarin.Forms:Map.IsShowingUser 未显示当前位置?

java - 如何将JFreeChart库添加到JDK?错误: package org. jfree.chart不存在

c++ - 尝试在 Codeblocks 上使用 Boost 库会给出未定义的引用

c++ - Visual C++ 2015 Tools for Windows 桌面安装程序无法打开

c++ - boost::mp11::mp_with_index 与 std::function 数组的性能比较

c++ - Visual Studio 2017 - 错误 MSB6006 : "CL.exe" exited with code 2

Azure SDK 在托管 VS2017 VSTS 构建代理上不可用?

java - 导入库导入的库?

c++ - 英特尔 SIMD 指令加速