小编ntd*_*ntd的帖子

Libtool为对象添加前缀,但gcov要求它们没有前缀

我需要gcov在我正在处理的共享库上执行一些测试覆盖.

问题是libtool将目标文件重命名为my-name.c,libmylib_la-my-name.lo并且gcov无法处理该转换.每次运行它时,cannot open notes file都会生成错误.

如果我手动重命名my-name.clibmylib_la-my-name.c后构建gcov工作正常,所以没有其他问题,除了文件名截断.

附录

试图提供一个最小的工作示例,我发现文件名修改只在lib..._la_CFLAGS设置时(以及设置为空值时)发生.

cat <<EOT > configure.ac
AC_INIT(sample,0.0.1)
AC_CONFIG_SRCDIR(configure.ac)
AM_INIT_AUTOMAKE(foreign)
LT_INIT
AC_PROG_CC
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
EOT

cat <<EOT > Makefile.am
lib_LTLIBRARIES=libsample.la
libsample_la_SOURCES=sample.c
# The following line triggers the filename mangling (libsample_la-sample.lo instead of sample.lo)
libsample_la_CFLAGS=
EOT

touch sample.c && autoreconf -if && ./configure && make
Run Code Online (Sandbox Code Playgroud)

有没有办法避免libtool操作的文件名修改或让我们gcov理解文件名修改方案?

c gcc autotools libtool gcov

8
推荐指数
1
解决办法
708
查看次数

关于C struct/union的可移植性问题

假设我从外部库中获得以下类型:

union foreign_t {
    struct {
        enum enum_t an_enum;
        int an_int;
    } header;
    struct {
        double x, y;
    } point;
};
Run Code Online (Sandbox Code Playgroud)

假设以下代码片段在不同平台和不同编译器上按预期工作是否安全?

struct pair_t {
    double x, y;
};

union foreign_t foreign;
struct pair_t *p_pair;

p_pair = (struct pair_t *) &foreign;
p_pair->x = 1234;
p_pair->y = 4321;

/* Expected result: (1234, 4321) or something like that */
printf("(%lf, %lf)", foreign.point.x, foreign.point.y);
Run Code Online (Sandbox Code Playgroud)

编辑:

按照严格的别名建议,我做了以下测试:

#include <stdint.h>
#include <stdio.h>

int main()
{
    uint16_t word = 0xabcd;
    uint8_t tmp;
    struct {
        uint8_t low; …
Run Code Online (Sandbox Code Playgroud)

c portability struct unions

3
推荐指数
1
解决办法
2391
查看次数

标签 统计

c ×2

autotools ×1

gcc ×1

gcov ×1

libtool ×1

portability ×1

struct ×1

unions ×1