找回密码
 register

QQ登录

只需一步,快速开始

搜索
查看: 37|回复: 1

[自写函数] 武侠世界编译过程中的一些报错

[复制链接]
  • 打卡等级:热心大叔
  • 打卡总天数:328
  • 打卡月天数:21
  • 打卡总奖励:326
  • 最近打卡:2025-10-28 00:24:01
Waylee 发表于 2025-10-22 16:57 | 显示全部楼层 |阅读模式 | Google Chrome | Windows 10

马上注册,查看网站隐藏内容!!

您需要 登录 才可以下载或查看,没有账号?register

×

报错一:

/home/wxsj2-master/Server/Server/Base/Log.cpp:27:9: 错误:invalid conversion from ‘char’ to ‘CHAR*’ {aka ‘char*’} [-fpermissive]
   27 |         '\0'
      |         ^~~~
      |         |
      |         char

为什么 MSVC 可能不报而 GCC 报

  • 旧 MSVC 对“字符串字面量 → char*”放宽;标准上这是不允许的,GCC/Clang 更严格。
  • '\0' 本质是 char,绝不可能自动变成 char*,这在任何标准编译器上都不应该通过。

修改方案:

const CHAR* g_pLogFileName[] = { /*...*/, "./Log/DBShare", '\0' };
//改为
const CHAR* g_pLogFileName[] = { /*...*/, "./Log/DBShare", nullptr };

报错二:

In file included from /home/wxsj2-master/ShareMemory/ShareMemory/../../Common/Type.h:28,
                 from /home/wxsj2-master/ShareMemory/ShareMemory/stdafx.h:22,
                 from /home/wxsj2-master/ShareMemory/ShareMemory/Main/CommandThread.cpp:1:
/home/wxsj2-master/ShareMemory/ShareMemory/../../Server/Server/SMU/SMUManager.h: 在成员函数‘void SMUManager<T>::Init()’中:
/home/wxsj2-master/ShareMemory/ShareMemory/../../Common/BaseType.h:86:22: 错误:return-statement with a value, in function returning ‘void’ [-fpermissive]
   86 |         #define TRUE 1
      |                      ^
/home/wxsj2-master/ShareMemory/ShareMemory/../../Server/Server/SMU/SMUManager.h:267:24: 附注:in expansion of macro ‘TRUE’
  267 |                 return TRUE;
      |                        ^~~~
/home/wxsj2-master/ShareMemory/ShareMemory/../../Common/BaseType.h:90:23: 错误:return-statement with a value, in function returning ‘void’ [-fpermissive]
   90 |         #define FALSE 0
      |                       ^
/home/wxsj2-master/ShareMemory/ShareMemory/../../Server/Server/SMU/SMUManager.h:269:24: 附注:in expansion of macro ‘FALSE’
  269 |                 return FALSE;
      |                        ^~~~~    

修正代码:

VOID        Init()
改为
BOOL        Init()

报错三

In file included from /usr/include/sql.h:19,
                 from /home/wxsj2-master/ShareMemory/ShareMemory/../../Common/DBSystem/DataBase/ODBCInterface.h:6,
                 from /home/wxsj2-master/ShareMemory/ShareMemory/Main/ShareMemory.cpp:9:
/usr/include/sqltypes.h:102:33: 错误:conflicting declaration ‘typedef unsigned int DWORD’
  102 | typedef unsigned int            DWORD;
      |                                 ^~~~~
In file included from /home/wxsj2-master/ShareMemory/ShareMemory/stdafx.h:22,
                 from /home/wxsj2-master/ShareMemory/ShareMemory/Main/ShareMemory.cpp:1:
/home/wxsj2-master/ShareMemory/ShareMemory/../../Common/Type.h:97:24: 附注:previous declaration as ‘typedef ULONG DWORD’
   97 |         typedef ULONG  DWORD;
      |                        ^~~~~

修改Type.h

#define DWORD uint32_t

错误:

[ 22%] Building CXX object Server/Server/CMakeFiles/Server.dir/Script/LuaFnRegister.cpp.o
In file included from /home/wx2Server-master/Server/Server/../../Common/Type.h:148,
                 from /home/wx2Server-master/Server/Server/stdafx.h:24,
                 from /home/wx2Server-master/Server/Server/Script/LuaFnRegister.cpp:9:
/home/wx2Server-master/Server/Server/Script/LuaFnTbl_Mission.h: 在函数‘int LuaFnTbl::LuaFnBeginEvent(lua_State*)’中:
/home/wx2Server-master/Server/Server/Script/LuaFnMacro.h:48:89: 错误:unable to find string literal operator ‘operator""FUNCNAME’ with ‘const char [16]’, ‘long unsigned int’ arguments
   48 |         Scene* pScene = (Scene*)(g_pSceneManager->GetScene(sceneId));   AssertEx(pScene,"场景ID出错 "FUNCNAME); if(pScene) {    \
      |                                                                                         ^~~~~~~~~~~~~~~~~~~~~
/home/wx2Server-master/Server/Server/../../Common/Assertx.h:47:106: 附注:in definition of macro ‘AssertEx’
   47 |         #define AssertEx(expr,msg) {if(!(expr)){__assertex__(__FILE__,__LINE__,__PRETTY_FUNCTION__,#expr,msg);}}
      |                                                                                                          ^~~
/home/wx2Server-master/Server/Server/Script/LuaFnTbl_Mission.h:60:17: 附注:in expansion of macro ‘BEGINSCENEDEFINE’
   60 |                 BEGINSCENEDEFINE("LuaFnBeginEvent")
      |                 ^~~~~~~~~~~~~~~~

"场景ID出错 "FUNCNAME 被编译器当成了用户自定义字面量(user-defined literal)——等价解析为 "场景ID出错 "_FUNCNAME,而你并没有定义 operator "" FUNCNAME,所以报:

unable to find string literal operator ‘operator""FUNCNAME’

这不是中文字符的问题,而是字符串字面量后面紧跟标识符且没有空格触发了 C++11 的 UDL 语法。

在 LuaFnMacro.h:48 把那一行改成在字符串和宏参数之间加一个空格,让它成为相邻字符串字面量的编译期拼接:

- AssertEx(pScene,"场景ID出错 "FUNCNAME);
+ AssertEx(pScene,"场景ID出错 " FUNCNAME);


  • 打卡等级:热心大叔
  • 打卡总天数:328
  • 打卡月天数:21
  • 打卡总奖励:326
  • 最近打卡:2025-10-28 00:24:01
 楼主| Waylee 发表于 2025-10-22 17:41 | 显示全部楼层 | Google Chrome | Windows 10
取消警告:cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-w" -DCMAKE_CXX_FLAGS="-w"
您需要登录后才可以回帖 登录 | register

本版积分规则

雪舞知识库 ( 浙ICP备15015590号-1 | 萌ICP备20232229号|浙公网安备33048102000118号 ) |网站地图|天天打卡

GMT+8, 2025-10-29 09:41 , Processed in 0.087199 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表