An issue with Matlab for a mex file compiled with GNU CYGWIN g++

Csaba Raduly rcsaba@gmail.com
Fri Jul 12 08:28:00 GMT 2013


Hi Emad,

On Fri, Jul 12, 2013 at 5:17 AM, Emad Gad  wrote:
(snip)
> And that led me to conclude that the i686-w64-mingw32-g++ is the way to go
(snip)

> The troubles I am having now is how to build the cmake-based project with
> i686-w64-mingw32-g++ compiler, through the cygwin shell? Somehow, I feel
> that this may be a contradiction in terms, but let me first report my
> observations.
>
> The main issue here is that the cmake that comes with cygwin will not accept
> the compiler i686-w64-mingw32-g++. It will complain that that compiler
> "cannot compile a simple file" which is a lie, because I know that it does.
> I actually tested, and Matlab used successfully. So how come cmake found out
> that it fails to compile?
>
> I found out the reason by invoking cmake with the option --debug-trycompile,
> and there I saw what cmake is trying to do and how it failed.
>
> cmake tests the compiler by requesting it to compile a very small file,
> called textCCompile.c, that it creates on the fly. However, its uses the
> absolute path of this file. To be more precise, here is the literal command
> that the /cygwinish/ cmake issues
>
> /cygdrive/c/MinGW64/mingw64/i686-w64-mingw32-g++ -o
> cmTryxxxxxxxx/testCCompile.c.o -c
> /home/usrername/path/to/the/file/build/CMakeFiles/CMakeTmp/testCCompile.c.
>
> The main problem here is that i686-w64-mingw32-g++ will not take the
> absolute path of the C file /home/usrername/path/to/the/file/testCCompile.c.
> Instead, it returns a "file not found" kind of error.

The problem is that /cygdrive/c/MinGW64/mingw64/i686-w64-mingw32-g++
is not a Cygwin program, so it interprets
/home/usrername/path/to/the/file/testCCompile.c differently from
Cygwin's cmake : as a path on the current drive, starting with a
directory named "home". However, Cygwin's /home is Windows'
C:\cygwin\home

Cygwin contains a utility called "cygpath" which can convert between
POSIX paths and Windows paths:

$ cygpath -w /home/usrername/path/to/the/file/testCCompile.c
C:\cygwin\home\usrername\path\to\the\file\testCCompile.c

Unfortunately, I don't think you can force cmake to pass all paths through it.

> So I feel now that the main problem is that mingw compiler, which worked
> with Matlab, the i686-w64-mingw32-g++, does not like UNIX-style absolute
> paths, and will not be able to grab any file specified using this mode.
>
> So my question is am I in the right place? Is it normal to use a
> cygwin-based cmake to compile a project with i686-w64-mingw32-g++?

It may be possible to force cmake to accept the compiler you specify
without checking, e.g. in the environment, like this:

CXX=/cygdrive/c/MinGW64/mingw64/i686-w64-mingw32-g++  cmake
--trust-the-compiler --the-compiler-is-your-friend path/to/sources

But it's likely that the makefiles it generates would also use POSIX
paths, and i686-w64-mingw32-g++ will not understand them unless you
hack the makefiles to use cygpath to translate filenames before make
passes them to i686-w64-mingw32-g++

I suspect it would be easier to use the native Windows version of
cmake with the mingw compiler.

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list