Question

I have some trouble with crosscompiling C++ program which takes advantage of openMP library. I am using Linux Ubuntu 12.04 LTS. I want to obtain executable file runnable on Windows.

I have no problem with compiling my program with OMP with regular g++ command:

  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:

 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:

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.

I found where omp.h file is located on my disk, and added the path to the command. 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

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

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. I have no idea what more I can do :(.

Était-ce utile?

La solution

First, @nmaier is completely correct in that the Ubuntu x86_64-w64-mingw32 toolchain is crippled, and that you can rebuild the toolchain yourself.

I, however, suggest that you use MXE, which saves you the time of manually compiling gcc and every dependency of it. 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

Autres conseils

Your x86_64-w64-mingw32 toolchain appears to have been build without libgomp.

  • You could check your supplier/distribution if it there additional or variant packages that have libgomp.
  • Or switch to a different supplier/distribution.
  • Or you could rebuild (or build in the first place) a cross gcc with --enable-libgomp. 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top