m0_53518584 2022-04-14 09:43 采纳率: 0%
浏览 91
已结题

__declspec(dllexport)和__declspec(dllimport)的使用

最近在研究涛思数据库,使用调库函数的方式实现sql的指令读写,但涛思的头文件中要用到的函数都是这样定义的:
#ifdef TD_GO_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif

DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...);
DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port);
DLL_EXPORT char *taos_get_server_info(TAOS *taos);
DLL_EXPORT char *taos_get_client_info();

这样看着是从dll导出的函数,我直接调用会报错无法解析的外部符号
taos_options(TSDB_OPTION_TIMEZONE,"CST");
TAOS* taos = taos_connect(m_taosip.c_str(),m_csUser.c_str(),m_csPasswd.c_str(),m_csDBname.c_str(),0);
char * info = taos_get_server_info(taos);
info = taos_get_client_info();
错误 8 error LNK1120: 4 个无法解析的外部命令
错误 6 error LNK2001: 无法解析的外部符号 _taos_connect
错误 5 error LNK2001: 无法解析的外部符号 _taos_get_server_info
错误 4 error LNK2001: 无法解析的外部符号 _taos_get_client_info
错误 7 error LNK2001: 无法解析的外部符号 _taos_options

在网上查了有关__declspec(dllexport)和__declspec(dllimport)的使用,但也会报错taos重定义之类的问题
#ifndef DLL_H_
#define DLL_H_

#ifdef DLLProvider
#define DLL_EXPORT_IMPORT __declspec(dllexport)
#else
#define DLL_EXPORT_IMPORT __declspec(dllimport)
#endif

DLL_EXPORT_IMPORT int taos_init();

#endif
错误 1 error C2375: “taos_init”: 重定义;不同的链接
4 IntelliSense: 重新声明无法将 dllexport/dllimport 添加到 "taos_init"

所以想请教下,这种在头文件里用了__declspec(dllexport)从dll输出的函数,应该怎么实现正常调用?

  • 写回答

1条回答 默认 最新

  • m0_53518584 2022-04-14 09:50
    关注

    补充一下,程序也配置了lib库的环境目录,库目录也配置了taos.lib,但还是会有无法解析的外部符号这个错误

    评论

报告相同问题?

问题事件

  • 系统已结题 4月22日
  • 创建了问题 4月14日

悬赏问题

  • ¥15 Opencv(C++)异常
  • ¥15 VScode上配置C语言环境
  • ¥15 汇编语言没有主程序吗?
  • ¥15 这个函数为什么会爆内存
  • ¥15 无法装系统,grub成了顽固拦路虎
  • ¥15 springboot aop 应用启动异常
  • ¥15 matlab有关债券凸性久期的代码
  • ¥15 lvgl v8.2定时器提前到来
  • ¥15 qtcp 发送数据时偶尔会遇到发送数据失败?用的MSVC编译器(标签-qt|关键词-tcp)
  • ¥15 cam_lidar_calibration报错