[英]OMP Cross compilation with x86_64-w64-mingw32-g++
I have some trouble with crosscompiling C++ program which takes advantage of openMP library. 使用openMP库的交叉编译C ++程序遇到一些麻烦。 I am using Linux Ubuntu 12.04 LTS. 我正在使用Linux Ubuntu 12.04 LTS。 I want to obtain executable file runnable on Windows. 我想获取Windows上可运行的可执行文件。
I have no problem with compiling my program with OMP with regular g++ command: 使用常规g ++命令使用OMP编译程序时,我没有任何问题:
g++ a.cpp b.cpp -o OMPres -pg -O3 -I./CBLAS/include -L./ -lcblas
Also when I try crosscompilation without OMP, everything runs perfectly fine: 另外,当我尝试不使用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
But when I try to crosscompile it with OMP using following command: 但是,当我尝试使用以下命令与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
I get this error: a.cpp:41:17: fatal error: omp.h: No such file or directory compilation terminated. 我收到此错误: a.cpp:41:17:致命错误:omp.h:没有此类文件或目录编译终止。
I found where omp.h file is located on my disk, and added the path to the command. 我找到了磁盘上的omp.h文件所在的位置,并在命令中添加了路径。 After executing it: 执行后:
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
I got another error: x86_64-w64-mingw32-g++: error: libgomp.spec: No such file or directory 我收到另一个错误: x86_64-w64-mingw32-g ++:错误:libgomp.spec:没有这样的文件或目录
As I also have this file on the disk I tried to copy it in various places and finaly it worked when I copied it directly into the directory where compilation takes place. 由于我还在磁盘上存储了该文件,因此我尝试在各个位置复制该文件,最后将其直接复制到进行编译的目录中时,该文件终于起作用了。 Then it produced another error: 然后产生了另一个错误:
/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 / usr / bin / x86_64-w64-mingw32-ld:找不到-lgomp / usr / bin / x86_64-w64-mingw32-ld:找不到-lrt collect2:ld返回1退出状态
I don't have a good understanding of how compilers exactly work. 我对编译器的工作方式不太了解。 I tried to update all mingw-w64 compilers that I could find with apt-cache search but nothing helped. 我试图更新所有可以通过apt-cache搜索找到的mingw-w64编译器,但没有任何帮助。 I have no idea what more I can do :(. 我不知道我还能做什么:(。
Your x86_64-w64-mingw32
toolchain appears to have been build without libgomp
. 您的x86_64-w64-mingw32
工具链似乎是在没有libgomp
情况下libgomp
。
libgomp
. 您可以检查供应商/分销商是否包含libgomp
其他软件包或变体软件包。 gcc
with --enable-libgomp
. 或者,您可以使用--enable-libgomp
重建(或首先构建)交叉gcc
。 This is kinda the hard way . 这有点困难 。 PS: Adding paths that do not correspond with your platform, like -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include
, is a bad idea in general, and will most certainly fail... This kinda creates a Franken-compiler. PS:添加与您的平台不匹配的路径,例如-I/usr/lib/gcc/x86_64-linux-gnu/4.6/include
,通常是一个坏主意,并且肯定会失败...这种情况会创建弗兰肯编译器。
First, @nmaier is completely correct in that the Ubuntu x86_64-w64-mingw32 toolchain is crippled, and that you can rebuild the toolchain yourself. 首先,@ nmaier是完全正确的,因为Ubuntu x86_64-w64-mingw32工具链已损坏,您可以自己重建该工具链。
I, however, suggest that you use MXE , which saves you the time of manually compiling gcc and every dependency of it. 但是,我建议您使用MXE ,它可以节省您手动编译gcc及其所有依赖项的时间。 The steps below should be enough for your purpose: 以下步骤足以满足您的目的:
# 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.