首页 文章

使用x86_64-w64-mingw32-g进行OMP交叉编译

提问于
浏览
1

我在使用openMP库的交叉编译C程序时遇到了一些麻烦 . 我使用的是Linux Ubuntu 12.04 LTS . 我想在Windows上获取可运行的可执行文件 .

用常规g命令用OMP编译我的程序没问题:

g++ a.cpp b.cpp -o OMPres -pg -O3 -I./CBLAS/include -L./ -lcblas

此外,当我尝试没有OMP的交叉编译时,一切都运行得很好:

x86_64-w64-mingw32-g++ a.cpp b.cpp -O3 -I./CBLAS/include ./CBLAS/cblas_WIN64.a ./BLAS/blas_WIN64.a -o res.exe -l gfortran -static

但是当我尝试使用以下命令使用OMP交叉编译它时:

x86_64-w64-mingw32-g++ a.cpp b.cpp -O3 -I./CBLAS/include ./CBLAS/cblas_WIN64.a ./BLAS/blas_WIN64.a -o OMPres.exe -l gfortran -static -fopenmp

我收到此错误: a.cpp:41:17: fatal error: omp.h: No such file or directory compilation terminated.

我发现omp.h文件位于我的磁盘上,并添加了命令的路径 . 执行后:

x86_64-w64-mingw32-g++ a.cpp b.cpp -O3 -I./CBLAS/include -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include ./CBLAS/cblas_WIN64.a ./BLAS/blas_WIN64.a -o OMPres.exe -l gfortran -static -fopenmp

我收到了另一个错误: x86_64-w64-mingw32-g++: error: libgomp.spec: No such file or directory

因为我在磁盘上也有这个文件,我试图在不同的地方复制它,最后它直接复制到编译发生的目录中 . 然后它产生了另一个错误:

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lgomp /usr/bin/x86_64-w64-mingw32-ld: cannot find -lrt collect2: ld returned 1 exit status

我对编译器的确切工作原理并不了解 . 我尝试更新所有使用apt-cache搜索找到的mingw-w64编译器,但没有任何帮助 . 我不知道我能做什么:( .

2 回答

  • 1

    首先,@ nmaier是完全正确的,因为Ubuntu x86_64-w64-mingw32工具链已经瘫痪了,你可以自己重建工具链 .

    但是,我建议你使用MXE,它可以节省你手动编译gcc及其依赖的时间 . 以下步骤应足以满足您的目的:

    # Get MXE
    git clone https://github.com/mxe/mxe.git && cd mxe
    
    # Settings
    cat <<EOF > settings.mk
    MXE_TARGETS := x86_64-w64-mingw32.static
    JOBS := 4
    EOF
    
    # Build gcc, libgomp, blas, and cblas. It will take a while
    make -j2 libgomp cblas
    
    # Add toolchain to PATH
    # See http://htmlpreview.github.io/?https://github.com/mxe/mxe/blob/master/index.html#tutorial step 4
    export PATH=`pwd`/usr/bin:$PATH
    
    # You don't need -I./CBLAS/include ./CBLAS/cblas_WIN64.a ./BLAS/blas_WIN64.a
    # because headers and libraries are installed to standard location and
    # I already used `-lcblas -lblas`.
    x86_64-w64-mingw32-g++ a.cpp b.cpp -fopenmp -O3 -o res.exe -lcblas -lblas -lgfortran -lquadmath
    
  • 1

    您的 x86_64-w64-mingw32 工具链似乎是在没有 libgomp 的情况下构建的 .

    • 如果有包含 libgomp 的附加或变体包,您可以检查供应商/分销 .

    • 或切换到其他供应商/分销 .

    • 或者您可以使用 --enable-libgomp 重建(或在第一个位置构建)一个交叉 gcc . 这有点难 .

    PS:添加与你的平台不对应的路径,比如 -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include ,一般来说是一个坏主意,并且肯定会失败......这有点创建了一个Franken编译器 .

相关问题