Bluebird’s blog
Black Green Blue Red Gold
RSS
  • Home PageHome
  • About Me

Windres problem and solution

, vi clones Add comments

A very technical post as first post on my blog. I publish the solution to a problem that we encountered yesterday, in the hope that it will help others.

Windres is an utility part of mingw or cygwin, that one uses on Windows to compile and add resources to an executable. An example of resources are the application icon, or the version information. There are more types but this is usually the one we are concerned about.

Our windres generation line part of our cmake build process is here:

   ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qyzis_ico.obj
                        COMMAND windres.exe
                            -I${CMAKE_CURRENT_SOURCE_DIR}
                            -o ${CMAKE_CURRENT_BINARY_DIR}/qyzis_ico.obj
                            -i${CMAKE_CURRENT_SOURCE_DIR}/qyzis_ico.rc
                        )
 

The problem we had was with path containing spaces. On windows, those are common beast. If you do a checkout on the desktop, the actual path of your checkout is C:\Document and vSettings\[User Name]\Desktop which contain spaces. If you run windres on a file in such a path, you get an error about gcc not finding the file. Why gcc while we are talking windres. The man page of windres gives the hint:

      --preprocessor program
          When  windres  reads  an  rc  file,  it  runs  it  through  the   C
          preprocessor  first.   This  option  may  be  used  to  specify the
          preprocessor to use, including any leading arguments.  The  default
          preprocessor argument is gcc -E -xc-header -DRC_INVOKED.

Oh, windres runs the rc files through the gcc preprocessor. But it does not quote them properly so gcc gets confused. We tried several combination of adding quotes and backslash to solve the problem, but it did not work. windres expects the filename unquoted and pass it like that to gcc.

Luckily, there is a way out of this. Two ways actually.

First solution :

There is a bug reported in the mingw bug tracker (I can find the reference now though) about this problem and a proposed fix. The bug has been closed and a fix is included in the mingw CVS. So, for the brave, you can recompile mingw and probably get rid or the problem.

Second solution :

The fix was quite trivial:

   ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qyzis_ico.obj
                        COMMAND windres.exe
                            -I${CMAKE_CURRENT_SOURCE_DIR}
                            -o ${CMAKE_CURRENT_BINARY_DIR}/qyzis_ico.obj
                            < ${CMAKE_CURRENT_SOURCE_DIR}/qyzis_ico.rc
                        )
 

Instead of specifying a file path to windres, we just pipe the file through its standard input. Works like a charm. You can thank orzel for that solution.


August 15th, 2007  

7 Responses to “Windres problem and solution”

  1. keeney
    May 19th, 2008 at 3:34 pm

    Thanks, it works!


  2. orzel
    May 19th, 2008 at 6:06 pm

    Nice to hear the blog has been useful for someone :-)


  3. Joshua
    October 1st, 2008 at 9:42 pm

    I had a similar problem, except I didn’t have any spaces in the path. Instead, windres wasn’t seeing the backslashes being passed to it. The problem turned out to be that codeblocks wasn’t calling MinGW’s windres — it was calling the first windres.exe found in my path — which happened to be Cygwin’s. I renamed cygwin’s windres.exe to something else and the problem was solved. A better “solution” is to place MinGW ahead of Cygwin in my path.


  4. admin
    October 2nd, 2008 at 11:23 am

    When using mingw, you should get rid or cygwin as much as you can. Usually, I simply discard cygwin and work in a dos shell. That’s really annoying in terms of shell capabilities but at the same time, it avoids tons of problems.


  5. AgiceRuidge
    November 4th, 2008 at 5:15 pm

    I don’t even know,fellow!) continued to write in the same vein, it is interesting people!


  6. David
    March 27th, 2009 at 2:51 pm

    Other alternative:

    ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/qyzis_ico.obj
    COMMAND windres.exe -I. -o ${CMAKE_CURRENT_BINARY_DIR}/qyzis_ico.obj -i qyzis_ico.rc
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    )

    Thanks for your post!


  7. orzel
    September 30th, 2009 at 2:00 am

    The trick doesn’t work anymore with gcc-4.4 (at least i think this is the reason why it doesnt work anymore).

    David : your atlernative does work, thanks a LOT for this!


Leave a Reply

  • RSS Thomas's blog

    • Announcing colibri 1.0 alpha1, a mailing list manager with a django based web interface April 3, 2010
    • Playing with clang and Qt January 10, 2010
    • How to use flex and bison with qmake (my own way) November 22, 2009
    • Wonders from a KDE fan and developer about some KDE design choices November 10, 2009
    • Installing an avr cross compiler in gentoo July 27, 2009
    • tags displayed in hg activity extension June 15, 2009
    • feedback about converting eigen2 to mercurial May 18, 2009
    • mercurial and ipv6 May 7, 2009
    • how to handle translations for an application that is both qt-only and KDE ? May 2, 2009
    • Fixing qmake missing rule for *.ts -> *.qm March 10, 2009
  • RSS Freehackers labs

    • Symia - 0.3 release brings few enhancements
    • Mercurial activity extension - Release 1.3
    • Colibri - First release for Colibri, 1.0-alpha1
    • PyTiCroque - PyTiCroque 0.5 est sorti.
    • Mercurial activity extension - Release 1.2
    • Symia - 0.2 released with misc fixes
    • Emerge activity - Release 1.0 for EmergeActivity
    • PyTiCroque - PyTiCroque 0.43 est sorti.
    • Symia - Announcing symia 0.1
    • Zeta Platform - Pre-compiled kernel for Zeta
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
Categories
  • python
  • vi clones
About Me

My name is Philippe, I am doing free software for fun, and propritary software for money and a little bit of fun as well.

Copyright © 2010 Bluebird’s blog All Rights Reserved XHTML CSS THEME by I SOFTWARE REVIEWS