我正在尝试编译一个库,但不断收到这些错误。不太 熟悉C但不知道如何解决这个问题。它不会创建 dll。
c:\>C:\tcc\tcc.exe C:\tcc\examples\hello_dll.c -o C:\tcc\examples\test_win.dll
tcc: error: undefined symbol 'hello_data'
tcc: error: undefined symbol 'hello_func'
//+---------------------------------------------------------------------------
//
// HELLO_DLL.C - Windows DLL example - main application part
//
#include <windows.h>
void hello_func (void);
__declspec(dllimport) extern const char *hello_data;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hello_data = "Hello World!";
hello_func();
return 0;
}
最佳答案
两个错误:
- hello_data 变量被声明为
extern
,这意味着它没有在此程序模块中定义,因此需要来自其他地方,来自同时链接的其他地方。 - 您的 WinMain 例程调用 hello_func,但它尚未定义。在 C 中,当您看到以
();
结尾的定义时,这意味着这是一个告诉编译器期望什么的原型(prototype),而不是该函数的实际代码。
我建议您首先计划启动一个控制台类型的应用程序,例如臭名昭著的 hello world,如下所示:
#include <stdio.h>
int main()
{
printf("Hello William\n");
}
这将在 MS Windows 下的 cmd 窗口中编译并运行。当你开始工作时,你可以考虑使用 Windows 环境和 DLL 中的 WinMain 等来做一些更奇特的事情。
关于c - TCC编译器: Undefined symbol “main” ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52909850/