Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
对任何问题,先规划,再执行
当你执行过程中遇到对工具的使用问题,经验教训记录回.cursorrules文件中

## 工程构建问题修复经验教训

### 1. C/C++项目中的重复定义问题
- 问题:头文件中包含全局变量定义导致重复定义错误
- 症状:`multiple definition of 'shutdown_server'` 链接错误
- 解决方案:将头文件中的变量定义改为`extern`声明,在一个源文件中实际定义变量
- 修复位置:`src/html_ui/html_game.h` 和 `src/html_ui/html_game.c`

### 2. CppUTest宏兼容性问题
- 问题:测试代码使用了不存在的CppUTest宏
- 症状:`'CHECK_C_LOCATION' was not declared in this scope` 编译错误
- 解决方案:使用正确的CppUTest宏`CHECK_TRUE_LOCATION`,并提供正确数量的参数
- 修复位置:`mahjong_evaluator/tst/test_terry_evaluator.cpp`

### 3. C语法错误
- 问题:宏定义中缺少分号,语句缺少分号
- 症状:`expected ';' before` 编译错误
- 解决方案:添加缺失的分号
- 修复位置:同上测试文件

### 4. 产品构建与测试构建的分离
- 问题:产品构建包含了测试框架依赖,导致链接错误
- 原因:CppUTest内存检测宏被自动包含,替换了标准malloc/free
- 解决方案:为产品构建创建不同的编译选项,或使用C++链接器处理C++库依赖
- 建议:在实际项目中应该有单独的产品构建配置

### 5. 项目结构理解
- 该项目是一个C语言实现的麻将游戏
- 包含HTTP服务器、游戏逻辑、AI代理、用户界面等模块
- 使用CppUTest作为单元测试框架
- 包含子项目mahjong_evaluator用于游戏评估逻辑
- 构建系统基于Makefile和CppUTest的MakefileWorker.mk
2 changes: 1 addition & 1 deletion cpputest
Submodule cpputest updated 468 files
6 changes: 3 additions & 3 deletions mahjong_evaluator/tst/test_terry_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ TEST_GROUP(evaluator_values)
int s2 = e(t2);
char temp[200];
sprintf(temp, "t1(%d) > t2(%d)", s1, s2);
CHECK_C_LOCATION(s1 > s2, temp, file, line);
CHECK_TRUE_LOCATION(s1 > s2, temp, "s1 > s2", temp, file, line);
}
};
#define T1_BIGGER_THAN_T2(t1, t2)\
compare_tile_strings_bigger(t1, t2, __FILE__, __LINE__)
compare_tile_strings_bigger(t1, t2, __FILE__, __LINE__);
TEST(evaluator_values, one_tile) {
T1_BIGGER_THAN_T2("2","1");
}
Expand Down Expand Up @@ -164,7 +164,7 @@ TEST(evaluator_values, 3_tiles) {
TEST(evaluator_values, 4_tiles) {
// T1_BIGGER_THAN_T2("1357","13BD");
T1_BIGGER_THAN_T2("2468","1357");
LONGS_EQUAL(e("1357"), e("3579"))
LONGS_EQUAL(e("1357"), e("3579"));
T1_BIGGER_THAN_T2("2467","2468");
T1_BIGGER_THAN_T2("2357","2468");
T1_BIGGER_THAN_T2("2346","2357");
Expand Down
3 changes: 3 additions & 0 deletions src/html_ui/html_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "agent.h"
#include "ui_agent.h"

// Define the global function pointer variable
void (*shutdown_server)(void) = NULL;

static int ui_adaptor_pool_add_ui_adaptor(agent_t * ui);
static agent_t * ui_adaptor_pool_get_ui_adaptor_by_id(int id);
static void ui_adaptor_pool_remove(int id);
Expand Down
2 changes: 1 addition & 1 deletion src/html_ui/html_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#define HTML_GAME_H_

int execute_game_command(const char * command, const char *parameters, char * buffer, int buffer_size);
void (*shutdown_server)(void);
extern void (*shutdown_server)(void);

#endif /* HTML_GAME_H_ */
Binary file added src/main.o
Binary file not shown.
Binary file added src/main_prod.o
Binary file not shown.