xpack icon indicating copy to clipboard operation
xpack copied to clipboard

clang 16.0.0-x86_64-pc-windows-msvc下编译不过

Open xiezhaokai opened this issue 1 year ago • 8 comments

问题如题. 在windows下,使用 clang 16.0.0-x86_64-pc-windows-msvc编译报错. 报错信息如下:

[build] 正在启动生成
[proc] 执行命令: chcp
[proc] 执行命令: "D:\Program Files\CMake\bin\cmake.EXE" --build d:/temp/xpack-clang/build --config Debug --target all --
[build] [1/2  50% :: 0.683] Building CXX object CMakeFiles/xpack-clang.dir/main.cpp.obj
[build] FAILED: CMakeFiles/xpack-clang.dir/main.cpp.obj 
[build] C:\LLVM\bin\clang++.exe  -ID:/temp/xpack-clang/include/xpack -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -MD -MT CMakeFiles/xpack-clang.dir/main.cpp.obj -MF CMakeFiles\xpack-clang.dir\main.cpp.obj.d -o CMakeFiles/xpack-clang.dir/main.cpp.obj -c D:/temp/xpack-clang/main.cpp
[build] D:/temp/xpack-clang/main.cpp:9:3: error: use of undeclared identifier 'X_PACK_L1_ENCODE'
[build]   XPACK(M(age, name));
[build]   ^
[build] D:/temp/xpack-clang/include/xpack/xpack.h:191:45: note: expanded from macro 'XPACK'
[build]     X_PACK_ENCODE_BEGIN X_PACK_N(X_PACK_L1, X_PACK_L1_ENCODE, __VA_ARGS__) return __x_pack_ret; }
[build]                                             ^
[build] D:/temp/xpack-clang/include/xpack/xencoder.h:150:16: note: in instantiation of function template specialization 'xpack::XEncoder<xpack::JsonWriter>::encode_struct<person>' requested here
[build]         return encode_struct(key, val, ext);
[build]                ^
[build] D:/temp/xpack-clang/include/xpack/json_encoder.h:273:12: note: in instantiation of function template specialization 'xpack::XEncoder<xpack::JsonWriter>::encode<person>' requested here
[build]         en.encode(NULL, val, NULL);
[build]            ^
[build] D:/temp/xpack-clang/include/xpack\json.h:50:19: note: in instantiation of function template specialization 'xpack::JsonEncoder::encode<person>' requested here
[build]         return en.encode(val);
[build]                   ^
[build] D:/temp/xpack-clang/main.cpp:17:29: note: in instantiation of function template specialization 'xpack::json::encode<person>' requested here
[build]   std::cout << xpack::json::encode(p) << std::endl;
[build]                             ^
[build] 1 error generated.
[build] ninja: build stopped: subcommand failed.
[proc] 命令“"D:\Program Files\CMake\bin\cmake.EXE" --build d:/temp/xpack-clang/build --config Debug --target all --”已退出,代码为 1
[driver] 生成完毕: 00:00:00.753
[build] 生成已完成,退出代码为 1

xpack.h中vscode显示该宏X_PACK_L1_ENCODE是启用的 请问该如何解决?

xiezhaokai avatar Feb 02 '24 01:02 xiezhaokai

你参考一下这个issue最后一个回复

xyz347 avatar Feb 02 '24 01:02 xyz347

哪个issue? @xyz347

xiezhaokai avatar Feb 02 '24 01:02 xiezhaokai

不好意思,漏贴链接了,https://gitee.com/xyz347/xpack/issues/I6P1EZ

xyz347 avatar Feb 02 '24 01:02 xyz347

@xyz347 我这边跟这个issue中有点不一样.

  1. 在vscode中,确认,xpack下的头文件和我的源文件都是utf8编码 (确定是 utf8无bom)
  2. 我是使用clang-windows-msvc下编译错误. 使用VS2017的MSVC是编译能通过(有warning,从“size_t”转换到“rapidjson::SizeType”),编辑器会报错(我使用的是clangd 插件).

xiezhaokai avatar Feb 02 '24 01:02 xiezhaokai

我这没有Windows环境,你看看你能用简单的代码复现吗?如果可以,我用Mac下的clang++看看能否复现。

xyz347 avatar Feb 02 '24 01:02 xyz347

github

使用cmake.确认使用vs2017编译通过,但是win上clang错误

xiezhaokai avatar Feb 02 '24 02:02 xiezhaokai

试了一下Mac上clang++,是没问题的。没环境,我这暂时没法查哈

xyz347 avatar Feb 02 '24 02:02 xyz347

好的,辛苦了.非常感谢~

xiezhaokai avatar Feb 02 '24 02:02 xiezhaokai

github

使用cmake.确认使用vs2017编译通过,但是win上clang错误

https://github.com/xyz347/xpack/blob/master/l1l2_expand.h 宏展开编译选项尝试修改为: if !defined(_MSC_VER) || defined(__clang__)

yinweihn avatar Mar 16 '24 07:03 yinweihn

@yinweihn 测试通过. 多谢~ 之前看到各种宏就头大,没深入看. 现在再看,估计clang的宏展开规则跟gcc的一致.之前的代码走msvc的定义去了~

xiezhaokai avatar Mar 21 '24 08:03 xiezhaokai

github 使用cmake.确认使用vs2017编译通过,但是win上clang错误

https://github.com/xyz347/xpack/blob/master/l1l2_expand.h 宏展开编译选项尝试修改为: if !defined(_MSC_VER) || defined(__clang__)

感谢,能否提个pr

xyz347 avatar Mar 21 '24 08:03 xyz347

PR: #47

xiezhaokai avatar Mar 21 '24 08:03 xiezhaokai