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

article/2025/11/4 21:35:10

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

  • 前言
  • 一. BUG提示
  • 二. 分析解决
  • 三. 小结

前言

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

一. BUG提示

1>------ 已启动生成: 项目: Project5, 配置: Debug x64 ------
1>  SoundTouchDLL.cpp
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(86): error C2491: “soundtouch_createInstance”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(104): error C2491: “soundtouch_destroyInstance”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(117): error C2491: “soundtouch_getVersionString”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(125): error C2491: “soundtouch_getVersionString2”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(133): error C2491: “soundtouch_getVersionId”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(140): error C2491: “soundtouch_setRate”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(151): error C2491: “soundtouch_setTempo”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(161): error C2491: “soundtouch_setRateChange”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(171): error C2491: “soundtouch_setTempoChange”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(181): error C2491: “soundtouch_setPitch”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(191): error C2491: “soundtouch_setPitchOctaves”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(201): error C2491: “soundtouch_setPitchSemiTones”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(211): error C2491: “soundtouch_setChannels”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(220): error C2491: “soundtouch_setSampleRate”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(235): error C2491: “soundtouch_flush”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(251): error C2491: “soundtouch_putSamples”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(266): error C2491: “soundtouch_putSamples_i16”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(297): error C2491: “soundtouch_clear”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(312): error C2491: “soundtouch_setSetting”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(326): error C2491: “soundtouch_getSetting”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(336): error C2491: “soundtouch_numUnprocessedSamples”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(353): error C2491: “soundtouch_receiveSamples”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(374): error C2491: “soundtouch_receiveSamples_i16”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(422): error C2491: “soundtouch_numSamples”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(432): error C2491: “soundtouch_isEmpty”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(441): error C2491: “bpm_createInstance”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(459): error C2491: “bpm_destroyInstance”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(474): error C2491: “bpm_putSamples”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.cpp(487): error C2491: “bpm_putSamples_i16”: 不允许 dllimport 函数 的定义
1>e:\project\vs\project5\project5\soundtouch\soundtouchdll.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)


http://chatgpt.dhexx.cn/article/ZqHp1GaC.shtml

相关文章

C#中DllImport使用法汇总

(转) 最近使用DllImport,从网上百度后发现,大部分内容都是相同,又从MSDN中搜集下,现将内容汇总,与大家分享。 大家在实际工作学习C#的时候,可能会问:为什么我们要为一些已经存在的功能&#xf…

dllexport和dllimport

在VS中,如果要跨项目使用类或变量,就必须用到dllexport和dllimport,下面分别举例全局变量,函数和类跨项目使用。 环境准备:使用VS分别新建一个windows应用程序和DLL项目,windows应用程序项目名称为ConsoleA…

简记C#DllImport异常

C#开发过程中,有些动态库引用不了,需要用DllImport加载该文件动态库; 然后在引用的过程中会碰到各种问题,当然网上各种回答,能解决大部分问题。 我在这里简单记录下问题的解决方案: ”尝试读取或写入受保…

关于c++动态库的dllexport和dllimport

先推荐一款比Microsoft Coplilot更好用的辅助编程工具——Cursor, 一款基于GPT4的新一代辅助编程神器——Cursor,官网介绍说是与OpenAI合作并且基于GPT4。自己体验了下,确实不错,值得尝试。 官网地址: Cursor | Build…

C# dllimport

一、DllImport是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL导出的函数的必要调用信息 DllImport的定义如下: public class DllImportAttribute:System.Attribute { public DllImportAttribute(string dllName) {……

C#中DllImport用法和路径问题

DllImport 是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL导出的函数的必要调用信息。 DllImport属性应应用于方法,要求最少要提供包含入口点的dll的名称。 文章目录 一 DllImport的定义如下:二 DllImpo…

1-5(中文版)听力积累

O 听力积累 KR 参照连接,建议看一看 听力学习步骤 选择材料:使用English Pod材料 Englishpod是一家公司叫做Praxis Language 推出的收费讲座。讲座高度还原生活场景,两位优秀的主持人以轻松聊天的方式讲解点评场景内容,在此过…

该如何拯救我的英语

说来羞愧,从初中开始,就算到大学本科毕业为止吧,英语也算得上是持续地学习了有 10 年时间了,十年啊,十年了,你知道这十年我是怎么。。。。emmm,十年时间就算是一天只记一个单词,那少…

英语磁带与计算机磁带区别,小学英语教材配听力磁带 家长:谁还用复读机?...

时间倒回十多年,大家听歌、听英语还是用磁带,复读机、录音机也是学生人手必备的学习用品。但在各种高端电子产品充斥的今天,再去找个录音机可能就非常困难了。这不?刚刚开学,就有小学一年级的家长被难倒了,…

小学听力测试英语软件,亲测:好用的小学英语软件有哪些?这6款通通安利给大家!...

原标题:亲测:好用的小学英语软件有哪些?这6款通通安利给大家! 首先,老师需要提前表明的是: 今天给大家推荐的这8款好用的小学英语软件,有的是我亲自测试过的,有的是同办公室的英语老…

什么软件能做英语测试卷听力,请问谁知道那些英语课本、期中期末考试的听力朗读的声音是怎么合成的?用什么软件?谢谢了...

满意答案 ceterry 2014.02.02 采纳率:57% 等级:12 已帮助:10834人 这些都是用 能说会道 XP 这个软件合成的,只需要课文的文字内容就可以转换成MP3的语音资料,还带LRC字幕,很方便,效果也好 “…

四六级英语听力软件测试,三款精品英语听力软件,提高四六级听力有诀窍

原标题:三款精品英语听力软件,提高四六级听力有诀窍 英语听力是所有英语考试中不可忽视的一个环节。然而在我们日常学习生活中,尤其是四六级备考,不乏只记单词不善听的情况,一个很重要的原因在于很多学生认为训练四六级听力太麻烦…

小学听力测试英语软件,你知道有哪些软件适合给小学生练习在线英语听力吗?...

前言: 随着英语听力软件在英语学习者当中的普及,如何挑选合适的听力软件倒成了技术活儿。你知道有哪些软件适合给小学生练习在线英语听力吗?今天为大家推荐3款好用的。 英语听力软件自推广以来,其趣味性和便捷性都是毋庸置疑的&am…

android英语听力播放器,掌上英语听力下载-掌上英语听力 安卓版v1.5.1-PC6安卓网...

掌上英语听力app是一款优质的英语听力练习软件。掌上英语听力app主要为用户提供专业的英语听写练习功能,有了掌上英语听力,使你进行英语听力练习更方便。 软件介绍 掌上英语听力是一款简单实用的英语听力软件,每天会推荐英语学习听力内容&…

剑桥标准英语教程听力资源1-4级

--------》 剑桥标准英语教程听力资源地址 书 名:剑桥标准英语教程4A:学生用书(附光盘1张) 作 者:Michael McCarthy, Jeanne McCarten, Helen Sandiford 出 版 社:北京语言大学出版社 书 名&#x…

网上英语听力测试的软件,初中英语听力测试

初中英语听力测试是一款专为初中学生打造的英语听力学习服务应用软件,初中英语听力测试app为用户提供了初一到初三的英语听力题库,并有中考听力真题试题和模拟试题。感兴趣的朋友欢迎使用西西下载! 基本内容 初中英语听力训练软件&#xff0c…

英语测试听力材料软件,英语听力软件哪个好?来这里!

原标题:英语听力软件哪个好?来这里! 智能手机现在几乎是人手一部了,但是每个人在使用智能手机的功能的时候却有不同的选择。喜欢英语的小伙伴会下载一些关于英语学习的软件,这样就能很好的利用碎片化的时间来提高自己的…

汇总linux下安装软件的几种方式------写的很好

转载地址:http://www.360doc.com/content/16/1006/11/29770038_596138348.shtml 安装软件---这个操作在WINDOWS的世界里很简单,下载软件双击exe文件即可,还有自动运行方式的,复杂点的执行bat之类的可执行程序即可。但Linux不然&am…

linux下如何安装软件

在Windows下安装 软件 时&#xff0c;只需用鼠标双击软件的安装程序&#xff0c;或者用Zip等解压缩软件解压缩即可安装。在Linux下安装软件对初学者来说&#xff0c;难度高于Windows下软件安装。下面我就详细讲解Linux下如何安装软件。 <script type"text/javascript&…

一文教你在Linux安装软件

Linux是个好东西&#xff0c;现在大多数服务器用的都是Linux操作系统。 不过我们通常需要在Linux上安装一些软件&#xff0c;在Windows上安装软件太简单了&#xff0c;不过在Linux上安装软件可能有些难度。不过没关系&#xff0c;本文将会交给你如何在Linux上安装软件。 本文介…