如何解决/usr/include/stdlib.h:133:35: 错误:在标记“(”之前缺少二元运算符
我在 gitlab ci-runners (Debian GNU/Linux 10 (buster)) 上编译带有 tizen 头文件的 gtest 项目时出现预处理错误。 gcc (Debian 8.3.0-6) 8.3.0
但在本地机器上 Ubuntu 16.04 编译成功。 gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
我安装了带有 SDK 的 Tizen Studion 4.1:WEaraBLE-5.5 和 knox_add_on_sdk_2.5.0。将 env PATH 导出到 tools/ide/bin 和包管理器,以及 tizen_include_root
要重现问题,您应该在 gtest 使用的项目中使用 #include
cmake_minimum_required(VERSION 3.5)
project(tests)
set (CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
include_directories(
#Tizen headers
if(DEFINED ENV{TIZEN_SDK_HOME})
SET(tizen_include_root "$ENV{TIZEN_SDK_HOME}/platforms/tizen-5.5/wearable/rootstraps/wearable-5.5-emulator.core/usr/include")
${tizen_include_root}/*
else()
message(WARNING "TIZEN_SDK_HOME env variable is not defined: tizen specific code completion and other features might not work")
endif()
)
include_directories(BEFORE
googletest/include
这样的错误:
Scanning dependencies of target gtest
[ 12%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
In file included from /usr/include/c++/8/cstdlib:75,from /usr/include/c++/8/ext/string_conversions.h:41,from /usr/include/c++/8/bits/basic_string.h:6400,from /usr/include/c++/8/string:52,from /usr/include/c++/8/bits/locale_classes.h:40,from /usr/include/c++/8/bits/ios_base.h:41,from /usr/include/c++/8/ios:42,from /usr/include/c++/8/ostream:38,from **DELETED**/src/test/googletest/include/gtest/gtest.h:56,from **DELETED**/src/test/googletest/src/gtest-all.cc:38:
/usr/include/stdlib.h:133:35: error: missing binary operator before token "("
#if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
^
/usr/include/stdlib.h:139:35: error: missing binary operator before token "("
#if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
^
/usr/include/stdlib.h:145:35: error: missing binary operator before token "("
#if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
或者这个:
In file included from /usr/include/x86_64-linux-gnu/bits/types/locale_t.h:22,from /usr/include/stdlib.h:272,from /usr/include/c++/8/cstdlib:75,from **DELETED**/src/test/googletest/src/gtest-all.cc:38:
/usr/include/x86_64-linux-gnu/bits/types/__locale_t.h:28:8: error: redeFinition of 'struct __locale_struct'
struct __locale_struct
如何将 tizen 和系统标头分开,我应该使用哪个标头?
解决方法
问题解决了。 在 CMakeList.txt 中使用编译器的直接路径帮助了我。
if(DEFINED ENV{TIZEN_SDK_HOME})
set(CMAKE_CXX_COMPILER $ENV{TIZEN_SDK_HOME}/tools/i586-linux-gnueabi-gcc-6.2/bin/i586-linux-gnueabi-g++)
您应该将 FLAGS 与 --sysroot 和 -L 一起用于 tizen 的库
SET(gcc_root "$ENV{TIZEN_SDK_HOME}/platforms/tizen-5.5/wearable/rootstraps/wearable-5.5-emulator.core")
set(CMAKE_C_FLAGS "--std=c99 ${CMAKE_C_FLAGS}")
set(CMAKE_C_STANDARD 99)
set (CMAKE_CXX_FLAGS "--std=c++14 --sysroot=${gcc_root} -L${gcc_root}/lib -L${gcc_root}/usr/lib ${CMAKE_CXX_FLAGS}")
还需要 LDFLAGS
export gcc_root=${TIZEN_SDK_HOME}/platforms/tizen-5.5/wearable/rootstraps/wearable-5.5-emulator.core
export LDFLAGS="--sysroot=${gcc_root} -L${gcc_root}/lib -L${gcc_root}/usr/lib"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。