静态调用dll时出现[Linker Error] Unresolved external错误

choge 2015-10-23 10:37:59
dll文件
//---------------------------------------------------------------------------

#include <windows.h>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------

#pragma argsused
//在DLL中实现一个求解N的阶乘的功能函数
extern "C" __declspec(dllexport) int __stdcall fac(int n);
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
int __stdcall fac(int n)
{
if(n==0)
return 1;
else
return(n*fac(n-1));
}


调用dll的文件
#pragma hdrstop

#include "TestUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
extern "C" __declspec(dllimport) int __stdcall fac(int n);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int i;
i=fac(StrToInt(Edit1->Text));
ShowMessage("结果是:"+AnsiString(i));
}

Build时出现[Linker Error] Unresolved external 'fac' referenced from D:\静态调用DLL\TESTUNIT.OBJ
...全文
269 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
choge 2015-11-02
  • 打赏
  • 举报
回复
感谢妖哥回复,不知为什么后来又行了
ccrun.com 2015-10-25
  • 打赏
  • 举报
回复
你需要将DLL工程生成的.lib文件添加到调用的工程中。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧