夥計!我以某種方式發現了一個更容易理解C語言中關於DLL的教程,但現在我似乎無法擺脫這個問題。DLL的問題
我創建了這個使用DLL的簡單程序。我打算在DLL中調用一個名爲「HelloWorld()」的函數,看它是否會顯示出我所希望的。
「dllmain.c」
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
DLLIMPORT void HelloWorld()
{
printf("HAI!");
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
{
break;
}
case DLL_PROCESS_DETACH:
{
break;
}
case DLL_THREAD_ATTACH:
{
break;
}
case DLL_THREAD_DETACH:
{
break;
}
}
/* Return TRUE on success, FALSE on failure */
return TRUE;
}
「dll.h」
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
#define DLLIMPORT __declspec(dllexport)
#else
#define DLLIMPORT __declspec(dllimport)
#endif
DLLIMPORT void HelloWorld();
#endif
「的main.c」(可執行)
#include <stdio.h>
#include <stdlib.h>
#include "dll.h"
#include <windows.h>
main()
{
HelloWorld();
getch();
}
這就是問題:
錯誤消息 {C:\文檔\ DLLTest \ main.o
main.c:(.text+0x10): undefined reference to `__imp_HelloWorld'}
{C:\...\Documents\DLLTest\collect2.exe [Error] ld returned 1 exit status
Can someone tell me why this appears?! Thanks in advance!}
哦,順便說一句,這是與DEVC++ TDM-GCC 4.7.1的64位版本
我可以問一下這可以做到嗎?我的意思是,我在哪裏可以在DevC++中找到這種選項? – Wix
@Wix我猜它使用gcc作爲編譯器?看看[本頁](http://www.tecgraf.puc-rio.br/iup/en/ide_guide/dev-cpp.html)如何將參數傳遞給「鏈接器」,傳遞「-ldllmain」在它之後有「庫目錄」,你在那裏傳遞dllmain.dll所在的目錄。 – 2014-01-18 15:49:41
對不起,但我還是不明白。你使用MS命令提示符做這個,還是使用Dev-C++ GUI有更簡單的方法嗎? – Wix