diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 0000000..f5ce124 --- /dev/null +++ b/.cursorrules @@ -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 \ No newline at end of file diff --git a/cpputest b/cpputest index 40d62a2..e332d88 160000 --- a/cpputest +++ b/cpputest @@ -1 +1 @@ -Subproject commit 40d62a2cec9fbf5626ea90f3afbe451ceb6dac8c +Subproject commit e332d88164090beba1060bd3159aea5ded3f5bba diff --git a/mahjong_evaluator/tst/test_terry_evaluator.cpp b/mahjong_evaluator/tst/test_terry_evaluator.cpp index d9bf50b..dc2d522 100644 --- a/mahjong_evaluator/tst/test_terry_evaluator.cpp +++ b/mahjong_evaluator/tst/test_terry_evaluator.cpp @@ -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"); } @@ -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"); diff --git a/src/html_ui/html_game.c b/src/html_ui/html_game.c index f3239ba..aa24185 100644 --- a/src/html_ui/html_game.c +++ b/src/html_ui/html_game.c @@ -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); diff --git a/src/html_ui/html_game.h b/src/html_ui/html_game.h index eb105ca..ac135c0 100644 --- a/src/html_ui/html_game.h +++ b/src/html_ui/html_game.h @@ -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_ */ diff --git a/src/main.o b/src/main.o new file mode 100644 index 0000000..4921fd5 Binary files /dev/null and b/src/main.o differ diff --git a/src/main_prod.o b/src/main_prod.o new file mode 100644 index 0000000..cc94a99 Binary files /dev/null and b/src/main_prod.o differ