`正在检查 mp_limb_t 的大小... 0`和`配置:错误:哎呀,mp_limb_t 似乎不起作用`

问题描述 投票:0回答:1

我无法弄清楚这一点。我正在尝试构建 Microchip XC32 PIC32 微控制器 GCC 交叉编译器。

自己尝试一下(这就是我陷入错误的原因):

  1. 在 Windows 10 或 Windows 11 上:启用“开发人员模式”以允许符号链接。 Windows键-->搜索“使用开发者功能”,单击按钮(现在下图中的蓝色)将其打开:

  2. 在此处克隆我的存储库:https://github.com/ElectricRCAircraftGuy/Microchip_XC32_Compiler

  3. 安装MSYS2,然后打开MSYS2 UCRT64 shell。或者,按照我的完整 MSYS2 设置说明进行操作

  4. 通过 pacman 安装依赖项,如下所示: 将整个 blob 一次性复制并粘贴到终端中:

    # ============= DO THIS TO INSTALL ALL DEPENDENCIES AT ONCE! =============
    # UCRT64
    if [ "$MSYSTEM" != "UCRT64" ]; then
        echo "ERROR: You must run this script in an MSYS2 ucrt64 terminal!"
        exit 1
    fi
    package_list=(
        "mingw-w64-ucrt-x86_64-gcc" # specific version for MSYS2 ucrt64
        "make"
        "binutils"
        "autoconf"
        "autogen"
        "bison"
        "dejagnu"
        "flex"
        "gawk"
        "gperf"
        "gzip"
        # "nsis" # generic; must be specific; hence the line below
        "mingw-w64-ucrt-x86_64-nsis" # specific version for MSYS2 ucrt64
        "perl"
        "scons"
        "tcl"
        "texinfo"
        "wget"
        "zip"
        # "texlive" # generic; must be specific; hence the line below
        "mingw-w64-ucrt-x86_64-texlive-core" # specific version for MSYS2 ucrt64
        # "texlive-extra-utils" # generic; must be specific; hence the line below
        "mingw-w64-ucrt-x86_64-texlive-extra-utils" # specific version for MSYS2 ucrt64
    )
    
    # Only install packages if tHey are NOT already installed. 
    for package in "${package_list[@]}"; do
        if ! pacman -Qs $package > /dev/null; then
            echo -e "\n=== $package is not installed. Installing... ==="
            pacman -S --noconfirm $package
        else
            echo -e "\n=== $package is already installed. ==="
        fi
    done
    echo -e "\n=== Done installing packages! ===\n"
    
  5. 运行构建脚本:

    build-xc32-v4.35m.sh
    :

    time ./build-xc32-v4.35m.sh
    
  6. 大约20分钟后,编译gcc失败,同时配置GMP。请注意,要获得干净的错误,您必须修改构建脚本以在第一行中使用

    -j1
    而不是
    -j$(nproc)
    ,否则您将在终端中得到相互重叠的多线程输出乱码:

    time make -j$(nproc) all-gcc \
         STAGE1_LIBS="-lexpat -lmchp -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic" \
         CPPFLAGS="-I${hostinstalldir}/include -imacros host-defs.h" \
         LDFLAGS=-L${hostinstalldir}/lib
    
    make install-gcc
    

这是我的失败。当 GMP 寻找

mp_limb_t
时,配置 GMP 似乎失败。我在下面用
<====
标记了一些注释/行:

checking for sysctl... no
checking for sysctlbyname... no
checking for times... no
checking for library containing clock_gettime... none required
checking for vsnprintf... yes
checking whether vsnprintf works... probably
configure: WARNING: cannot check for properly working vsnprintf when cross compiling, will assume it's ok
checking whether sscanf needs writable input... no
checking for struct pst_processor.psp_iticksperclktick... no
checking size of void *... 8
checking size of unsigned short... 2
checking size of unsigned... 4
checking size of unsigned long... 4
checking size of mp_limb_t... 0                           <===== SIZE SHOULD BE 8
configure: error: Oops, mp_limb_t doesn't seem to work    <===== ERROR
make: *** [Makefile:4701: configure-gmp] Error 1

real    3m27.324s
user    0m1.373s
sys     0m30.921s
Error: [gcc] failed to build!

real    3m27.510s
user    0m1.373s

请注意,一旦我安装了依赖项,构建脚本就可以在 Ubuntu 22.04 上完美运行完成。这是 MSYS2 中的 Windows,我无法让它工作。非常感谢任何帮助。这将有助于 PIC32 社区使用 GCC 进行构建,而无需从 Microchip 购买许可证。交叉编译器是 GPL 许可的。

我也在这里留下了更详细的评论:https://github.com/JuliaLang/julia/issues/13206#issuecomment-1791823912。我不再认为符号链接是问题,因为我尝试直接将数据复制到符号链接上而不进行任何更改。

我在这里提供了自动生成的

Makefile
gcc/gmp/config.log
文件:https://github.com/ElectricRCAircraftGuy/Microchip_XC32_Compiler/tree/main/temp_debug_files。我已在该目录中的 README.md 文件中描述了它们。

在这个问题上已经坚持了好几天了。可以使用一些社区支持。


如果有人想在 MSYS2 MINGW64 环境中尝试它,以下是如何在该终端中安装这些依赖项:

# ============= DO THIS TO INSTALL ALL DEPENDENCIES AT ONCE! =============
# mingw64
if [ "$MSYSTEM" != "MINGW64" ]; then
    echo "ERROR: You must run this script in an MSYS2 mingw64 terminal!"
    exit 1
fi
package_list=(
    "mingw-w64-x86_64-gcc" # specific version for MSYS2 mingw64
    "make"
    "binutils"
    "autoconf"
    "autogen"
    "bison"
    "dejagnu"
    "flex"
    "gawk"
    "gperf"
    "gzip"
    # "nsis" # generic; must be specific; hence the line below
    "mingw-w64-x86_64-nsis" # specific version for MSYS2 mingw64
    "perl"
    "scons"
    "tcl"
    "texinfo"
    "wget"
    "zip"
    # "texlive" # generic; must be specific; hence the line below
    "mingw-w64-x86_64-texlive-core" # specific version for MSYS2 mingw64
    # "texlive-extra-utils" # generic; must be specific; hence the line below
    "mingw-w64-x86_64-texlive-extra-utils" # specific version for MSYS2 mingw64
)

# Only install packages if tHey are NOT already installed. 
for package in "${package_list[@]}"; do
    if ! pacman -Qs $package > /dev/null; then
        echo -e "\n=== $package is not installed. Installing... ==="
        pacman -S --noconfirm $package
    else
        echo -e "\n=== $package is already installed. ==="
    fi
done
echo -e "\n=== Done installing packages! ===\n"

这是感兴趣的自动生成的 Makefile 块:

C:\Users\gabriel\GS\dev\Microchip_XC32_Compiler\xc32-v4.35-src\pic32m-build\gcc\Makefile

.PHONY: configure-gmp maybe-configure-gmp
maybe-configure-gmp:
maybe-configure-gmp: configure-gmp
configure-gmp: 
    @r=`${PWD_COMMAND}`; export r; \
    s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
    test ! -f $(HOST_SUBDIR)/gmp/Makefile || exit 0; \
    $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gmp; \
    $(HOST_EXPORTS)  \
    echo Configuring in $(HOST_SUBDIR)/gmp; \
    cd "$(HOST_SUBDIR)/gmp" || exit 1; \
    case $(srcdir) in \
      /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) ;; \
      *) topdir=`echo $(HOST_SUBDIR)/gmp/ | \
        sed -e 's,\./,,g' -e 's,[^/]*/,../,g' `$(srcdir) ;; \
    esac; \
    module_srcdir=gmp; \
    $(SHELL) \
      $$s/$$module_srcdir/configure \
      --srcdir=$${topdir}/$$module_srcdir \
      $(HOST_CONFIGARGS) --build=${build_alias} --host=none-${host_vendor}-${host_os} \
      --target=none-${host_vendor}-${host_os} --disable-shared LEX="touch lex.yy.c" \
      || exit 1

更多线索需要跟进:

  1. https://www.google.com/search?q=bug%3A+msys2+doesnt+accept+absolute+paths+in+gcc&oq=bug%3A+msys2+doesnt+accept+absolute+paths+in+ gcc&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIGCAEQRRg60gEJMTQ5NDNqMGo0qAIAsAIA&client=ms-android-google&sourceid=chrome-mobile&ie=UTF-8
  2. https://stackoverflow.com/a/39256699/4561887
  3. https://github.com/msys2/MINGW-packages/issues/6711#issuecomment-662982274

自我注意:我认为包含中的前导

/
可能会被MSYS GCC解释为
C:\
,这意味着
/c/my/path
被视为
C:\c\my\path
而不是
C:\my\path
。然而,这与 MSYS 终端的处理方式相反。真是个皮塔饼啊。研究上面的来源。

使用

realpath --relative-to
转换为构建脚本中的相对路径。也更新我的 Stack Overflow 答案:https://stackoverflow.com/a/60157372/4561887

c++ gcc mingw-w64 gmp msys2
1个回答
0
投票

解决了。

修复

更改这部分

build-xc32-v4.35m.sh

# Finally, GCC.
PS4="[gcc] "
(
    set -ex

    rm -rf ${gcc_builddir}
    mkdir -p ${gcc_builddir}
    cd ${gcc_builddir}

    ${gcc_srcdir}/configure \
    # ...

对此。唯一的变化是创建和使用

gcc_srcdir_RELATIVE
来使用相对路径而不是绝对路径调用
configure
脚本!:

# Finally, GCC.
PS4="[gcc] "
(
    set -ex

    rm -rf ${gcc_builddir}
    mkdir -p ${gcc_builddir}
    cd ${gcc_builddir}

    # Obtain relative paths, since Windows doesn't like absolute paths due to Windows/Linux path
    # differences in gcc includes.
    gcc_srcdir_RELATIVE=$(realpath --relative-to="." "${gcc_srcdir}")

    ${gcc_srcdir_RELATIVE}/configure \
    # ...

说明

通过这样做,

srcdir
文件顶部的
Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-build/gcc/Makefile
变量会从这里的绝对路径更改

srcdir = /c/Users/gbriel/GS/dev/Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-source/gcc
到这里的相对路径:

srcdir = ../../pic32m-source/gcc

这在同一个 Makefile 中。请注意,topdir=$(srcdir)

--srcdir=$${topdir}/$$module_srcdir
 被传递到对 
configure
 库的 
gmp
 的调用。

.PHONY: configure-gmp maybe-configure-gmp maybe-configure-gmp: maybe-configure-gmp: configure-gmp configure-gmp: @r=`${PWD_COMMAND}`; export r; \ s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \ test ! -f $(HOST_SUBDIR)/gmp/Makefile || exit 0; \ $(SHELL) $(srcdir)/mkinstalldirs $(HOST_SUBDIR)/gmp; \ $(HOST_EXPORTS) \ echo Configuring in $(HOST_SUBDIR)/gmp; \ cd "$(HOST_SUBDIR)/gmp" || exit 1; \ case $(srcdir) in \ /* | [A-Za-z]:[\\/]*) topdir=$(srcdir) ;; \ *) topdir=`echo $(HOST_SUBDIR)/gmp/ | \ sed -e 's,\./,,g' -e 's,[^/]*/,../,g' `$(srcdir) ;; \ esac; \ module_srcdir=gmp; \ $(SHELL) \ $$s/$$module_srcdir/configure \ --srcdir=$${topdir}/$$module_srcdir \ $(HOST_CONFIGARGS) --build=${build_alias} --host=none-${host_vendor}-${host_os} \ --target=none-${host_vendor}-${host_os} --disable-shared LEX="touch lex.yy.c" \ || exit 1
嗯,gmp 

configure

 脚本使用该 
--srcdir
 参数来设置此包含,如 
in Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-build/gcc/gmp/config.log
 中所示

configure:27432: gcc -c -g -O2 -D__USE_MINGW_ACCESS -DNO_ASM -I/c/Users/gabriel/GS/dev/Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-build/opt/include -imacros host-defs.h conftest.c >&5 conftest.c:80:10: fatal error: /c/Users/gabriel/GS/dev/Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-source/gcc/gmp/gmp-h.in: No such file or directory 80 | #include "/c/Users/gabriel/GS/dev/Microchip_XC32_Compiler/xc32-v4.35-src/pic32m-source/gcc/gmp/gmp-h.in" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.
并且,由于 

这个非 bug ,Windows 上的 MSYS2 gcc 中不允许绝对 Linux 风格包含

奇怪的是,将绝对路径作为命令行参数传递给
g++

可以工作,但将其用作 include 则不行。

例如

g++ -c /c/Users/travis/build/config.cpp

有效,即它找到 
cpp

文件,并将

/c/...
路径转换为
C:/...
路径,但给出包含错误:
C:/Users/travis/build/config.cpp:1:10: fatal error: /c/Users/travis/build/config.hpp: No such file or directory

    1 | #include "/c/Users/travis/build/config.hpp"

      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

因此,通过调用 
${gcc_srcdir_RELATIVE}/configure

,现在包含的内容在自动生成的

conftest.c
文件中看起来像这样,并且效果很好!:
#include "../../../pic32m-source/gcc/gmp/gmp-h.in"

现在我正在解决这个构建过程中的下一个错误。 :/

参考文献

从我的问题的底部:

    Google 搜索“bug:msys2 不接受 gcc 中的绝对路径”
  1. msys2 下的 gcc 和 clang 无法解析包含绝对路径的内容
  2. gcc/g++ 无法包含绝对路径的文件
© www.soinside.com 2019 - 2024. All rights reserved.