c++ - 奇怪的编译器行为

标签 c++ gcc boost cross-compiling uclibc

我正在尝试编译我的项目,它使用了 boost。 我的主要整数类型是 sys/types.h 中的 int32_tint64_t。 如果我使用主机系统编译器(GCC 4.8.3、x86_64)编译项目,过程成功完成并且二进制文件是正确的,但如果我尝试使用外部工具链(GCC 4.3.5、armv5te)交叉编译到 ARM,过程中断在

Using built-in specs.
Target: arm-unknown-linux-uclibcgnueabi
Configured with: /home/vijay/sdk/SDK6.1/04_Software/05_ToolChain/02_Source/buildroot-2010.11-r46561/output/toolchain/gcc-4.3.5/configure --prefix=/opt/Mozart_Toolchain/arm-eabi-uclibc/usr --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c,c++ --with-sysroot=/opt/Mozart_Toolchain/arm-eabi-uclibc --with-build-time-tools=/opt/Mozart_Toolchain/arm-eabi-uclibc/usr/arm-unknown-linux-uclibcgnueabi/bin --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-libssp --disable-multilib --disable-tls --enable-shared --with-gmp=/home/vijay/sdk/SDK6.1/04_Software/05_ToolChain/02_Source/buildroot-2010.11-r46561/output/toolchain/gmp --with-mpfr=/home/vijay/sdk/SDK6.1/04_Software/05_ToolChain/02_Source/buildroot-2010.11-r46561/output/toolchain/mpfr --disable-nls --enable-threads --disable-decimal-float --with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=arm926ej-s --with-pkgversion='Buildroot 2010.11' --with-bugurl=http://bugs.buildroot.net/
    Thread model: posix
    gcc version 4.3.5 (Buildroot 2010.11) 
    arm-linux-g++ -c -O3 -g -lprotobuf -lboost_system -lboost_thread -lcrypto -lboost_random -lboost_program_options -lboost_filesystem -lboost_chrono -lesyslog -lesyslog2stderr  -L/home/dcow/Work/Libs/Release/libesyslog/ -L../../ROOT/lib/ -I./ -I../common/ -I../common/protobuf/ -I../export/ -I../../libESyslog/ -I../../ROOT/include/ -DLINUX_GCC  eventmanager.cpp -o eventmanager.o
    In file included from eventmanager.h:8,
                     from eventmanager.cpp:3:
    serversession.h:20: error: reference to 'int32_t' is ambiguous
    /opt/Mozart_Toolchain/arm-eabi-uclibc/usr/include/sys/types.h:197: error: candidates are: typedef int int32_t
    ../../ROOT/include/boost/cstdint.hpp:260: error:                 typedef int boost::int32_t
    serversession.h:20: error: reference to 'int32_t' is ambiguous
    /opt/Mozart_Toolchain/arm-eabi-uclibc/usr/include/sys/types.h:197: error: candidates are: typedef int int32_t
    ../../ROOT/include/boost/cstdint.hpp:260: error:                 typedef int boost::int32_t
    serversession.h:20: error: 'int32_t' does not name a type
    In file included from eventmanager.cpp:7:
    networkmanager.h:64: error: reference to 'int32_t' is ambiguous
    cc1plus: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error>
    ../../ROOT/include/boost/cstdint.hpp:260: error:                 typedef int boost::int32_t
    networkmanager.h:64: error: reference to 'int32_t' is ambiguous
    cc1plus: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error>
    ../../ROOT/include/boost/cstdint.hpp:260: error:                 typedef int boost::int32_t
    networkmanager.h:64: error: 'int32_t' does not name a type
    In file included from eventmanager.cpp:8:
    subscriptionsmanager.h:29: error: reference to 'int64_t' is ambiguous
    cc1plus: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error>
    ../../ROOT/include/boost/cstdint.hpp:308: error:                 typedef boost::long_long_type boost::int64_t
    subscriptionsmanager.h:29: error: expected ',' or '...' before 'messageId'
    subscriptionsmanager.h:29: error: ISO C++ forbids declaration of 'int64_t' with no type
    subscriptionsmanager.h:30: error: reference to 'int64_t' is ambiguous
    cc1plus: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error>
    ../../ROOT/include/boost/cstdint.hpp:308: error:                 typedef boost::long_long_type boost::int64_t
    subscriptionsmanager.h:30: error: expected ',' or '...' before 'messageId'
    subscriptionsmanager.h:30: error: ISO C++ forbids declaration of 'int64_t' with no type
    eventmanager.cpp: In member function 'bool rvi::EventManager::handleAuthorization(ObjectId&, NVRMessage&)':
    eventmanager.cpp:177: error: reference to 'int64_t' is ambiguous
    cc1plus: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error>
    ../../ROOT/include/boost/cstdint.hpp:308: error:                 typedef boost::long_long_type boost::int64_t
    eventmanager.cpp:177: error: reference to 'int64_t' is ambiguous
    cc1plus: error: candidates are: #'tree_list' not supported by dump_decl#<declaration error>
    ../../ROOT/include/boost/cstdint.hpp:308: error:                 typedef boost::long_long_type boost::int64_t
    eventmanager.cpp:177: error: expected `;' before 'messageId'
    eventmanager.cpp:179: error: 'messageId' was not declared in this scope
    make: *** [eventmanager.o] Error 1

我没有使用 using namespace boost

我如何编译 boost:

cd $(BOOST_SOURCES_DIR)
./bootstrap.sh --prefix=$(ROOT_DIR)
echo "using gcc : arm : arm-unknown-linux-uclibcgnueabi-g++ ;" > tools/build/v2/user-config.jam
./b2 toolset=gcc-arm link=shared --with-system --with-random --with-thread --with-signals --with-regex --with-filesystem --with-date_time --with-program_options --with-chrono -threading=multi  install 

最佳答案

Boost 的 <boost/cstdint.hpp>定义与 uclibc 的 sys/types.h 冲突。

这不应该发生。你可能有 using namespace boost;在不适当的地方(在标题中或包含库标题之前)。

关于c++ - 奇怪的编译器行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24823347/

相关文章:

C# BlockingCollection 的 c++/boost 模拟?

c++ - 根据传入命令选择和执行任务的模式/架构

c++ - 将 std::vector 转换为数组

面向 Ruby 脚本编写者的 C++

c++ - 为什么类类型的静态和全局变量是危险的?

c++ - 如何在 GCC 中使用 OpenSSL?

c - 带有自定义注册说明符的 GCC snprintf

c++ - boost::aligned_storage 在返回时像 POD 类型一样复制非 POD 对象

c++ - 数组不是命名空间::std 的成员

c++ - Boost 序列化/反序列化存档 "stream error"异常