/usr/include/stdlib.h:133:35: error: missing binary operator before token "("

/usr/include/stdlib.h:133:35: error: missing binary operator before token "("

我在 gitlab ci-runners (Debian GNU/Linux 10 (buster)) 上使用 tizen headers 编译 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 和 package-manager,以及 tizen_include_root

要重现问题,您应该在 gtest 使用的项目中使用 #include 并在 include_directories(...[=13= 中使用 tizen headers 的绝对路径]

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 /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/x86_64-linux-gnu/bits/types/__locale_t.h:28:8: error: redefinition of 'struct __locale_struct'
 struct __locale_struct

如何分离 tizen 和系统 headers 我应该使用哪个?

问题已解决。 在 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"