当前位置: 首页 > 工具软件 > STLPort > 使用案例 >

使用linaro gcc-5.4.1为tx2-ubuntu16.04 交叉编译STLPort库报错:[...no member named ‘__tm_gmtoff’]的解决办法

帅煌
2023-12-01

由于需要交叉编译的Poco库依赖stlport库,

所以从STLPort的官方下载了一份最新的源代码[5.2.1]准备交叉编译到TX2环境。

拿到源代码后感觉很不爽,STLPort并不支持cmake和autotools, 映入眼帘的是一个configure 可执行脚本,

运行一下帮助看看是否支持交叉编译工具配置:

$ ./configure --help
Configuration utility.

Usage:

  configure [options]

Available options:

  --prefix=<dir>        base install path (/usr/local/)
  --bindir=<dir>        install path for executables (PREFIX/bin)
  --libdir=<dir>        install path for libraries (PREFIX/lib)
  --includedir=<dir>    install path for headers (PREFIX/include)

  --target=<target>     target platform (cross-compiling)

  --help                print this help message and exit

  --with-stlport=<dir>  use STLport in catalog <dir>
  --without-stlport     compile without STLport
  --with-boost=<dir>    use boost headers in catalog <dir>
  --with-system-boost   use boost installed on this system
  --with-msvc=<dir>     use MS VC from this catalog
  --with-mssdk=<dir>    use MS SDK from this catalog
  --with-extra-cxxflags=<options>
                        pass extra options to C++ compiler
  --with-extra-cflags=<options>
                        pass extra options to C compiler
  --with-extra-ldflags=<options>
                        pass extra options to linker (via C/C++)
  --use-static-gcc      use static gcc libs instead of shared libgcc_s (useful for gcc compiler,
                        that was builded with --enable-shared [default]; if compiler was builded
                        with --disable-shared, static libraries will be used in any case)
  --clean               remove custom settings (file /home/nvidia/workspace/STLport-5.2.1/build/Makefiles/gmake/config.mak)
                        and use default values
  --with-cxx=<name>     use <name> as C++ compiler (use --target= for cross-compilation)
  --with-cc=<name>      use <name> as C compiler (use --target= for cross-compilation)
  --use-compiler-family=<name> use compiler family; one of:
                        gcc      GNU compilers (default)
                        icc      Intel compilers
                        aCC      HP's aCC compilers
                        CC       SunPro's CC compilers
                        bcc      Borland's compilers
  --without-debug       don't build debug variant
  --without-stldebug    don't build STLport's STLP_DEBUG mode
  --enable-static       build static
  --disable-shared      don't build shared 
  --with-lib-motif=<motif>
                        Use this option to customize the generated library name.
                        The motif will be used in the last place before version information,
                        separated by an underscore, ex:
                        stlportd_MOTIF.5.0.lib
                        stlportstld_static_MOTIF.5.1.lib
  --without-thread      Per default STLport libraries are built in order to be usable
                        in a multithreaded context. If you don't need this you can ask
                        for a not thread safe version with this option.
  --without-rtti        Disable RTTI when building libraries.
  --with-static-rtl
  --with-dynamic-rtl
                        Enables usage of static (libc.lib family) or dynamic (msvcrt.lib family)
                        C/C++ runtime library when linking with STLport. If you want your appli/dll
                        to link statically with STLport but using the dynamic C runtime use
                        --with-dynamic-rtl; if you want to link dynamicaly with STLport but using the
                        static C runtime use --with-static-rtl. See README.options for details.
                        Don't forget to signal the link method when building your appli or dll, in
                        stlport/stl/config/host.h set the following macro depending on the configure
                        option:
                        --with-static-rtl  -> _STLP_USE_DYNAMIC_LIB"
                        --with-dynamic-rtl -> _STLP_USE_STATIC_LIB"
  --windows-platform=<name>
                        Targetted OS when building for Windows; one of:
                        win95   Windows 95
                        win98   Windows 98
                        winxp   Windows XP and later (default)

Environment variables:

  $CXX                 C++ compiler name (use --target= for cross-compilation)
  $CC                  C compiler name (use --target= for cross-compilation)
  $CXXFLAGS            pass extra options to C++ compiler
  $CFLAGS              pass extra options to C compiler
  $LDFLAGS             pass extra options to linker (via C/C++)

  Options has preference over environment variables.

存在--prefix选项,说明可以设置make install 的安装路径

没有看到--host选项,这个可能没有办法像autotools 的configure那么方便的配置交叉工具链了。

注意到最后几行可以通过导出CXX, CC变量的形式来实现交叉编译。

制作一个编译脚本:

#!/bin/bash
SRC_ROOT_DIR=$PWD
BUILD_DIR=${SRC_ROOT_DIR}/build-for-aarch64-ubuntu16.04
INSTALL_DIR=${BUILD_DIR}/install
CROSS_COMPILE_PREFIX=aarch64-linux-gnu
CC=${CROSS_COMPILE_PREFIX}-gcc
CXX=${CROSS_COMPILE_PREFIX}-g++

echo "CC=${CC}"
echo "CXX=${CXX}"

if [ -d ${BUILD_DIR} ]
then
	echo "${BUILD_DIR} exists";
else
	mkdir -p ${BUILD_DIR}
fi

export PATH=${PATH}:/usr/local/bin/linaro-5.4.1/bin
export CXX=aarch64-linux-gnu-g++
export CC=aarch64-linux-gnu-gcc
./configure \
--prefix=${INSTALL_DIR} \

make -j11

make install

在执行脚本的时候报找不到符号错误:

../../src/time_facets.cpp: In function ‘void stlp_std::priv::__write_formatted_timeT(stlp_std::priv::__basic_iostring<_CharT>&, const stlp_std::ctype<_CharT>&, char, char, const _TimeInfo&, const tm*)’:
../../src/time_facets.cpp:434:19: error: ‘const struct tm’ has no member named ‘__tm_gmtoff’
         diff = t->__tm_gmtoff;
                   ^

找到对应的代码行,发现STLPort报错所指向的这段代码受宏预编译控制:

#    if defined (__USE_BSD) || defined (__BEOS__)
        diff = t->tm_gmtoff;
#    else
        diff = t->__tm_gmtoff;
#    endif

而结构体的原型出处在工具链的time.h文件中

struct tm
{
  int tm_sec;			/* Seconds.	[0-60] (1 leap second) */
  int tm_min;			/* Minutes.	[0-59] */
  int tm_hour;			/* Hours.	[0-23] */
  int tm_mday;			/* Day.		[1-31] */
  int tm_mon;			/* Month.	[0-11] */
  int tm_year;			/* Year	- 1900.  */
  int tm_wday;			/* Day of week.	[0-6] */
  int tm_yday;			/* Days in year.[0-365]	*/
  int tm_isdst;			/* DST.		[-1/0/1]*/

# ifdef	__USE_MISC
  long int tm_gmtoff;		/* Seconds east of UTC.  */
  const char *tm_zone;		/* Timezone abbreviation.  */
# else
  long int __tm_gmtoff;		/* Seconds east of UTC.  */
  const char *__tm_zone;	/* Timezone abbreviation.  */
# endif
};

我这里的__USE_MISC宏默认是打开的,所以定义了tm_gmtoff成员,但是却没定义__tm_gmtoff成员。

将STLPORT的time_facets.cpp中宏编译选项修改为如下:

#    if defined (__USE_BSD) || defined (__BEOS__) || defined(__USE_MISC)
        diff = t->tm_gmtoff;
#    else
        diff = t->__tm_gmtoff;
#    endif

再执行一次编译,成功了

$ ./build-for-aarch64-ubuntu16.04.sh 

以上,解决使用linaro gcc-5.4.1为tx2-ubuntu16.04 交叉编译STLPort库报错:[...no member named ‘__tm_gmtoff’]的问题。

 类似资料: