From 4c3d99f8e662b1570c39a9831eac1667d980e119 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 9 Oct 2025 01:47:12 +0000 Subject: [PATCH 1/2] Initial commit of modified files from installation Co-authored-by: zhang.lyuan --- cpputest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpputest b/cpputest index 40d62a2..e332d88 160000 --- a/cpputest +++ b/cpputest @@ -1 +1 @@ -Subproject commit 40d62a2cec9fbf5626ea90f3afbe451ceb6dac8c +Subproject commit e332d88164090beba1060bd3159aea5ded3f5bba From 656944581dbfc29f75201b744e713ba905db2b06 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Thu, 9 Oct 2025 01:52:01 +0000 Subject: [PATCH 2/2] Fix build errors and add documentation Co-authored-by: zhang.lyuan --- .cursorrules | 35 ++++++++++++++++++ .../tst/test_terry_evaluator.cpp | 6 +-- src/html_ui/html_game.c | 3 ++ src/html_ui/html_game.h | 2 +- src/main.o | Bin 0 -> 3168 bytes src/main_prod.o | Bin 0 -> 1528 bytes 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 .cursorrules create mode 100644 src/main.o create mode 100644 src/main_prod.o 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/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 0000000000000000000000000000000000000000..4921fd5367bb43e9fe05a1acb37fe4673d800968 GIT binary patch literal 3168 zcmb_eO=uit7=C9bv)%0GXR~RW#8|Ubm$pKuNd%P^+f`}1LhvA@)PqcCcPE=A`xAC% z)2N6-K@1h~q{Wk7#Dizgg2h5F6$CGyi$w}rya=tt_nG6o+#81R zaAF)Cc9a_n3*qLP#zJb+dMcFZ_uE%K>t&z+dGz+3cW3@uFN_e4rr06Gtd+^$wNmMC zt%K<|twLtn8s(Ns=Pswx98a6Gwi4o;&>!ZUBlKW5VTerLq$HT^kpz>pL#Y{ z(WLA^(Ik`dnl=zkDhw1QeZ_r2t5c5GZ_Fn}c{qf>G=#@iCB<1EVt;c8|HTkq&J|V^ ztMOee=#O=kS{ zeo*gT?Kr;I%&(t=3lCfuG-Ouw~#p zj=$D&8+)RoC<>ZwPqE&*v)1GK_@#C`b@H~oT0iidsAQfpNcDi*JeR<&lI_3UM*n}{ z2ye80ekJA~>d>9ULC_FW!}A3WXIDpADf0fvSp4n4UBf*oi-GF@R7HKGbevTwji^qh^ zKlowDw=~lB+dj<$N%{X)`L~rL)(`JaJpUQykbjYzjyYA-1)XGBYL)&yjnhpXWf0$Q z@e^CrmsJ0zI)Adys2^`ty#6PcL(F*nU6lyyt3&cj|1}SatlNE_L?+lih`3GtEkm3e z%Kt?u8l--q?z50I|Bn*pkMEWE%ewr^TvDk&DY7exR3Eqfh54lXU#k2S<%jjhUdHp| zd?03g{m-cdIm}}^B)|0E@u0b~i!wjZ?e3}k@~uREK>Q+&sKi8k?J;&)k+Ki)!@sV0 G{r>`mnJp3k literal 0 HcmV?d00001 diff --git a/src/main_prod.o b/src/main_prod.o new file mode 100644 index 0000000000000000000000000000000000000000..cc94a999a09641f7aaa5c967dd0b3388918daba6 GIT binary patch literal 1528 zcmbu9&ubGw6vy8tX_AIkf+z^}5WH9ghon6y9!j*-<`6t6Im$BGOw-{0D7&*Y3ZhU@ zLKXZI#FHKc5A~#=(7#0R;6ZO53h}+&neDR4p8Uew_vSNi=FQH`?z64#oq}P2mH``Z z+R_wYTs)22QP_qWX7)OhADx3=_2aD*qOGr!)lWD9Kj7h}k=rq4X5Oo!;jHY>f8Zob=_&UZU%BOAD`8Nroh%cgP zew!eQ>ekRSZ(vNK6G)%JLaDM?D_4Q}!sbkhu>@v$jw4(NL+%LE;?0-w7B5MyD5QkZdlTns^~!7N~b^d;}3f9#O|Uwyy{QlDfp-50e9T8 zkQn*2+Nz=Nv+m2@X&Oss)z%5h|5b(Ft2Ui6ElGcR7ZhJYPpM7S*6x)GRy9ywO`H6i zHj!(VPW_Z_q~dJu(|G)z+O8z?NJTdi5(j$y8jmrU_x^9yg!(<{{b`T&c+Kx4D|V+I ly60$#j?{SimPj<7lwJQvWZAV--fw!Ks%ii^x+mHC{{V74x=a87 literal 0 HcmV?d00001