编译log4cxx出错
Tofloor
poster avatar
lisisong
deepin
2017-11-01 23:45
Author


提示转换出错,但是看代码并没有错误,gcc的问题?
Reply Favorite View the author
All Replies
avatar
134******40
deepin
2017-11-02 09:16
#1
本帖最后由 jdocker 于 2017-11-2 01:50 编辑

大概意思是诸如超过大小超过0x7B的东西不是有符号char型。如果用有符号char型数组,那么就需要强制类型转换,例如0x7C超过了0x7B,那么就需要强制类型转换。
你可以在前面加上强制类型转换。如 (char)0x7C ,其他依次类推。因为新的gcc对这种错误会报错。后续碰到这种错误,就按照定义的数组类型进行转换。如果是charlog类型,可别用(char) 0x7C 强制类型转换,而是用(charlog)转换。
这个库还有几个文件的头文件导入有点问题(以官网下载的0.1.0源码为例,github得来的不要尝试,那基本上不能成功)。
  1. src/main/cpp/inputstreamreader.cpp 添加#include   
  2. src/main/cpp/socketoutputstream.cpp 添加#include   
  3. src/examples/cpp/console.cpp 添加#include
Copy the Code
Reply View the author
avatar
134******40
deepin
2017-11-02 09:38
#2
本帖最后由 jdocker 于 2017-11-2 02:00 编辑

还有官方仓库已经集成了liblog4cxx-dev了,你可以直接安装
  1. sudo apt install liblog4cxx-dev
Copy the Code
Reply View the author
avatar
134******40
deepin
2017-11-02 10:41
#3
提供一个可编译通过的版本,按照错误提示调整过的版本:
Reply View the author
avatar
134******40
deepin
2017-11-02 17:56
#4
如果使用这个版本,你在deepin系统下需要先安装好这些(官方说明有点问题,安装有点异常):
  1. sudo apt install libapr1-dev libaprutil1-dev doxygen
Copy the Code

然后使用已经修正过得版本或者你自己按照错误修改的版本(推荐你自己修改,这样你可以知道为什么错)。
然后
  1. #配置
  2. ./configure
  3. #编译
  4. make -j4
  5. #安装
  6. sudo make install
Copy the Code

Reply View the author
avatar
loword
deepin
2021-10-27 07:01
#5
        char prolog[] = {
         0x72, 0x00, 0x21, 0x6F, 0x72, 0x67, 0x2E, 
         0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2E, 0x6C, 
         0x6F, 0x67, 0x34, 0x6A, 0x2E, 0x73, 0x70, 0x69, 
         0x2E, 0x4C, 0x6F, 0x63, 0x61, 0x74, 0x69, 0x6F, 
         0x6E, 0x49, 0x6E, 0x66, 0x6F, (char)0xED, (char)0x99, (char)0xBB, 
         (char)0xE1, 0x4A, (char)0x91, (char)0xA5, (char)0x7C, 0x02, 0x00, 0x01, 
         0x4C, 0x00, 0x08, 0x66, 0x75, 0x6C, 0x6C, 0x49, 
         0x6E, 0x66, 0x6F, 
            0x74, 0x00, 0x12, 0x4C, 0x6A, 
                0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 
                0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
         0x78, 0x70 };
Reply View the author
avatar
loword
deepin
2021-10-27 07:11
#6

loggingevent.cpp: In static member function 'static void log4cxx::spi::LoggingEvent::writeProlog(log4cxx::helpers::ObjectOutputStream&, log4cxx::helpers::Pool&)':
loggingevent.cpp:292:26: error: narrowing conversion of '243' from 'int' to 'char' inside { } [-Wnarrowing]
         0x3B, 0x78, 0x70 };
                          ^
loggingevent.cpp:292:26: error: narrowing conversion of '242' from 'int' to 'char' inside { } [-Wnarrowing]
loggingevent.cpp:292:26: error: narrowing conversion of '185' from 'int' to 'char' inside { } [-Wnarrowing]
loggingevent.cpp:292:26: error: narrowing conversion of '181' from 'int' to 'char' inside { } [-Wnarrowing]

     char classDesc[] = {
        0x72, 0x00, 0x21, 
        0x6F, 0x72, 0x67, 0x2E, 0x61, 0x70, 0x61, 0x63, 
        0x68, 0x65, 0x2E, 0x6C, 0x6F, 0x67, 0x34, 0x6A, 
        0x2E, 0x73, 0x70, 0x69, 0x2E, 0x4C, 0x6F, 0x67, 
        0x67, 0x69, 0x6E, 0x67, 0x45, 0x76, 0x65, 0x6E, 
        0x74, (char)0xF3, (char)0xF2, (char)0xB9, 0x23, 0x74, 0x0B, (char)0xB5, 
Reply View the author