我想编译一些可以download here的C++软件。这是从2001年开始的。运行make应该可以解决问题。

我在Ubuntu 10.10上,必须将makefile中的gcc更改为g++才能正常工作。

警告:

现在,程序需要扫描参数文件。编译时,我收到几个警告:

g++    -c -o packet_data_agent.o packet_data_agent.cpp
packet_data_agent.cpp: In constructor ‘PACKET_DATA_AGENT::PACKET_DATA_AGENT()’:
packet_data_agent.cpp:34: warning: deprecated conversion from string constant to ‘char*’
packet_data_agent.cpp: In member function ‘void PACKET_DATA_AGENT::initialize(FILE*, FILE*)’:
packet_data_agent.cpp:109: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:128: warning: format ‘%d’ expects type ‘int*’, but argument 3 has type ‘int32*’
packet_data_agent.cpp:131: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:136: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:141: warning: format ‘%d’ expects type ‘int*’, but argument 3 has type ‘int32*’
packet_data_agent.cpp:144: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:149: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp: In member function ‘int32 PACKET_DATA_AGENT::get_PDU(int32, VIRTUAL_PDU*)’:
packet_data_agent.cpp:213: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp:244: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp: In member function ‘void PACKET_DATA_AGENT::put_PDU(int32, VIRTUAL_PDU*)’:
packet_data_agent.cpp:312: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int32’
packet_data_agent.cpp: In member function ‘void PACKET_DATA_AGENT::write_statistics(FILE*)’:
packet_data_agent.cpp:393: warning: format ‘%10d’ expects type ‘int’, but argument 3 has type ‘int32’
packet_data_agent.cpp:394: warning: format ‘%10d’ expects type ‘int’, but argument 3 has type ‘int32’
g++ -O4  mobile_ip.o loss_generator.o radio_link_agent.o packet_data_agent.o -o mobile_ip -lm

我的问题:

这些导致我无法解析包含的设置文件。在packet_data_agent.h中,变量声明为int32:
int32 compressed_Internet_header_size;

和C++代码来扫描packet_data_agent.cpp:128中的参数文件:
fscanf(ParameterFile_ptr,"- compressed RTP/UDP/IP header size (in bytes): %d\n",&compressed_Internet_header_size);

但是,当我运行该程序时,出现以下错误:
!!error in module PACKET-DATA-AGENT: illegal value 0 for the compressed RTP/UDP/IP header size

尽管参数文件显然具有:
- compressed RTP/UDP/IP header size (in bytes): 3

如何使程序正确解析参数文件?

附加信息:
  • 我的平台上int的大小为4

  • 这是我的g++版本:
    $ g++ -v
    Using built-in specs.
    Target: i686-linux-gnu
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
    Thread model: posix
    gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
    

    一些非常简单的调试:

    我将源代码更改如下:
    int return_test = fscanf(ParameterFile_ptr,"- compressed RTP/UDP/IP header size (in bytes): %d\n",&compressed_Internet_header_size);
    printf ("%d\n", return_test);
    printf ("%d\n", compressed_Internet_header_size);
    

    输出为0,0。这意味着什么?我的意思是说真的,它就在我眼前,找不到参数?

    最佳答案

    警告:

    header global.h使int32成为long的同义词。当您在格式为long*printf中传递%dint时,gcc会发出警告,因为在某些平台上(任何long为32位且int为64位,或者long为16位且int32为32的平台)不好的结果。

    您可以更改typedef,以便int表示long而不是int,并且可能不会发生任何不良情况。

    运行时的实际错误:

    [根据原始提问者的新信息进行编辑:]

    看来这与long / int32 / fscanf的东西无关:相反,fscanf无法读取参数文件的这一行。那之前的那行呢? fscanf是为它们全部返回1,还是实际上以更早的方式出错而不会停止尝试解析文件?

    假设所有先前的file containing the output RTP stream调用均成功,并且这是第一个失败的调用:如果将固定的样板内容从源代码复制并粘贴到文件中,会发生什么情况?如果您只寻找没有固定样板文字的数字怎么办?您的参数文件中的compressed RTP/UDP/IP header size行和fscanf行之间没有其他行了吗?

    您可能可以对失败的地方有所了解,如下所示:令人讨厌的fread调用之后,使用fscanf读取一部分参数文件,显示该文件,然后退出(当然,继续尝试毫无用处;解析器将如果您完全感到困惑)。例如,如果由于遇到了与ojit_code格式字符串中的常量文本不匹配的字符而失败,则应该为您提供不匹配的字符以及随后出现的一些字符。如果由于尝试读取一个整数而看到它不喜欢的东西而失败了,那么您应该获取第一个无法解释为整数一部分的字符,以及随后出现的一些字符。等等。

    关于c++ - 某些旧的C++软件编译期间的警告(格式应为int类型,参数为int32),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5377455/

    10-14 10:57
    查看更多