使用c ++程序中的dll。 (borland c ++ builder和一般) [英] Use a dll from a c++ program. (borland c++ builder and in general)

查看:436
本文介绍了使用c ++程序中的dll。 (borland c ++ builder和一般)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一个dll,即libcurl,与我的程序,但是,它不是链接。 libcurl自带的.h文件,我可以包括(照顾dllimport),但是我想我必须指定哪个dll实际上使用链接的时候...如何做到这一点?我正在编译Borland C ++ builder,但我真的想知道这些东西是如何工作的一般...

I'm trying to use a dll, namely libcurl, with my program, but, it's not linking. Libcurl comes with .h files that I can include (takes care of dllimport), but then I guess I must specify which dll to actually use when linking somehow... How do I do that? I'm compiling with Borland C++ builder, but I really want to know how these things work in general...

编辑:
这是代码直接来自curl主页的c / p)

This is the code (straight c/p from curl homepage)

bool FTPGetFile::ConnectToFTP(string ftpServer){
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
    res = curl_easy_perform(curl);
    return true;
}else{
    return false;
}
} 

这里是错误:


[Linker Error] Error: Unresolved external '_curl_easy_init' referenced from C:\PROJECTS\PC\TOOLBOX\DEBUG_BUILD\FTPGETFILE.OBJ
[Linker Error] Error: Unresolved external '_curl_easy_setopt' referenced from C:\PROJECTS\PC\TOOLBOX\DEBUG_BUILD\FTPGETFILE.OBJ
[Linker Error] Error: Unresolved external '_curl_easy_perform' referenced from C:\PROJECTS\PC\TOOLBOX\DEBUG_BUILD\FTPGETFILE.OBJ

编辑2:根据建议从joe_muc我已经使用implib工具创建了lib文件,并将它们包含在链接器路径中。我仍然得到相同的错误。

EDIT 2: As per suggestion from joe_muc I have made the lib files with the implib tool and included them in the linker path. I still get the same errors.

推荐答案

如上所述,您将需要与.dll一起的静态.lib文件您可以通过implib运行
并将结果lib文件添加到您的项目中。

As mentioned, you will need the static .lib file that goes with the .dll which you run through implib and add the result lib file to your project.

如果您这样做了:


  • 您可能需要使用stdcall调用约定。
    您没有提到您使用的是哪个版本的Builder,但
    通常是在项目选项 - 高级编译器 - 调用约定下。

  • 您可能需要启用MFC兼容性选项。

  • 可能是名称问题(项目选项 - C ++兼容性选项)。


  • 或高级链接器选项Case_insensitive-link开启或关闭

  • You may need to use the stdcall calling convention. You didn't mention which version of Builder you are using, but it is usually under Project options - Advanced compiler - Calling convention.
  • You may need to enable MFC compatibility option.
  • It could be a name mangling issue (Project options - C++ compatiblity options).
  • Or generation underscores
  • Or advanced linker options "Case_insensitive-link" on or off

libcurl看起来是C代码;但如果是C ++,注意Microsoft和Borland类一般不兼容。应该有办法让他们工作,但它是一个真正的混乱处理,我从来没有成功。 C编译的DLL应该工作。

libcurl appears to be C code; but if it is C++, note that Microsoft and Borland classes are generally not compatible. There are supposed to be tricks to get them to work, but it is a real mess to deal with and I have never had success. C coded DLLs should work.

这篇关于使用c ++程序中的dll。 (borland c ++ builder和一般)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆