c - TCC 编译器:未定义符号“main”
问题描述
我正在尝试编译一个库,但不断收到这些错误。对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 语言中,当您看到以它结尾的定义时,
();
这意味着这是一个原型,用于告诉编译器期望什么,而不是函数的实际代码。
我建议首先,您计划启动一个控制台类型的应用程序,例如臭名昭著的 hello world,例如:
#include <stdio.h>
int main()
{
printf("Hello William\n");
}
这将在 MS Windows 下的 cmd 窗口中编译和运行。当你开始工作时,你可以考虑使用 Windows 环境和 DLL 中的 WinMain 之类的东西来做一些更有趣的事情。
推荐阅读
- c# - C# SQL Server 连接字符串与同一服务器上的多个数据库
- c# - 在android中使用GZIP压缩流
- c++ - 递归地依赖于自身的概念特化的价值是什么?
- python - Django:无法在管理面板中注册模型
- spring - Thymeleaf 片段内容不替换主要内容?
- python - 制作一个刷新按钮
- javascript - Node.js - TypeError: res.json is not a function(在某些路由中工作而不在其他路由中工作)
- javascript - 如何打开一个新窗口(音乐播放器)并将其托管在 Shopify 环境中
- python - 使用 API 进行身份验证扫描的有效 OWASP Zap 脚本示例
- tabs - 带有子选项卡的 Flutter Appbar(操作)