栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

VS BUG(5) error C2491: “****“: 不允许 dllimport 函数 的定义

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

VS BUG(5) error C2491: “****“: 不允许 dllimport 函数 的定义

VS BUG(5) error C2491: "****": 不允许 dllimport 函数 的定义
  • 前言
  • 一. BUG提示
  • 二. 分析解决
  • 三. 小结

前言

程序员难免要与BUG打交道,本系列将记录自己在VS平台下代码调试过程中遇到的一些BUG,希望对大家遇到相关问题时,可以提供帮助。

一. BUG提示
1>------ 已启动生成: 项目: Project5, 配置: Debug x64 ------
1>  SoundTouchDLL.cpp
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(86): error C2491: “soundtouch_createInstance”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(104): error C2491: “soundtouch_destroyInstance”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(117): error C2491: “soundtouch_getVersionString”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(125): error C2491: “soundtouch_getVersionString2”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(133): error C2491: “soundtouch_getVersionId”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(140): error C2491: “soundtouch_setRate”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(151): error C2491: “soundtouch_setTempo”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(161): error C2491: “soundtouch_setRateChange”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(171): error C2491: “soundtouch_setTempoChange”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(181): error C2491: “soundtouch_setPitch”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(191): error C2491: “soundtouch_setPitchOctaves”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(201): error C2491: “soundtouch_setPitchSemiTones”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(211): error C2491: “soundtouch_setChannels”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(220): error C2491: “soundtouch_setSampleRate”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(235): error C2491: “soundtouch_flush”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(251): error C2491: “soundtouch_putSamples”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(266): error C2491: “soundtouch_putSamples_i16”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(297): error C2491: “soundtouch_clear”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(312): error C2491: “soundtouch_setSetting”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(326): error C2491: “soundtouch_getSetting”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(336): error C2491: “soundtouch_numUnprocessedSamples”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(353): error C2491: “soundtouch_receiveSamples”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(374): error C2491: “soundtouch_receiveSamples_i16”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(422): error C2491: “soundtouch_numSamples”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(432): error C2491: “soundtouch_isEmpty”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(441): error C2491: “bpm_createInstance”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(459): error C2491: “bpm_destroyInstance”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(474): error C2491: “bpm_putSamples”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(487): error C2491: “bpm_putSamples_i16”: 不允许 dllimport 函数 的定义
1>e:projectvsproject5project5soundtouchsoundtouchdll.cpp(522): error C2491: “bpm_getBpm”: 不允许 dllimport 函数 的定义
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
二. 分析解决

在进行语音变速不变调的工程集成应用中,调试时出现上述报错。查询资料可知原工程调用了生成的dll动态链接库,为了减少使用dll时候的设置或者代码编写,因此需要修改dll.h文件中的相关代码,在dll.h文件开头添加如下代码

#ifndef DLL_EXPORT
   #define DECLDIR __declspec(dllimport)
#else
   #define DECLDIR __declspec(dllexport)
#endif

本工程是基于SoundTouchDLL.h进行应用,首先添加DLL_EXPORTS到项目-》属性-》C/C+±》预处理器-》预处理器定义中如下图所示

在SoundTouchDLL.h文件中的存在此部分代码如下:

 #ifdef DLL_EXPORTS
        #define SOUNDTOUCHDLL_API extern "C" __declspec(dllexport)
    #else
        #define SOUNDTOUCHDLL_API extern "C" __declspec(dllimport)
    #endif

因此无需再进行修改(添加完上述预处理器定义后,工程内的报错提示即已消失),首先清理解决方案后,直接重新生成解决方案,如下图所示生成成功。

再进行调试运行如下图所示

运行成功,问题解决。

三. 小结

这个问题是在项目移植过程中出现的,主要原因是宏定义未被识别,故报错,根据相关提示直接在预处理器定义中添加缺失的宏定义一般问题都可以得到解决。希望本文可以帮助到大家解决这个BUG,再给大家两个参考链接。

不允许dllimport函数的定义

c ++:不允许使用dllimport函数的定义,使用visual studio 2010构建(c++: definition of dllimport function not allowed, building with visual studio 2010)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/960019.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号