Bluebird's blog
Black Green Blue Red Gold
RSS
  • Home PageHome
  • About me
  • Free software

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 15:34

    Thanks, it works!


  2. orzel
    May 19th, 2008 at 18:06

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


  3. Joshua
    October 1st, 2008 at 21:42

    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

    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 17:15

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


  6. David
    March 27th, 2009 at 14:51

    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 02:00

    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

  • Pages

    • About me
    • Free software
      • Old Free Software Interviews
  • RSS Thomas’s blog

    • Compiling firefox-9.0 on linux PPC January 11, 2012
    • DjangoRedmineAdmin 1.0 released January 8, 2012
    • Celery init scripts for Gentoo December 2, 2011
    • New lightweight admin-oriented linux kernel mercurial mirror November 14, 2011
    • EmergeActivity gets a graphical interface: releasing 2.0 November 9, 2011
    • A small step forward for the mercurial activity plugin, releasing version 2.0 September 18, 2011
    • How to detect Altivec availability on linux/ppc at runtime May 13, 2011
    • Mercurial mirror for Django stable branch 1.3 April 7, 2011
    • announcing qxv October 3, 2010
    • New mercurial mirror for Django stable branch 1.2 September 9, 2010
  • RSS Freehackers labs

    • Django Redmine Admin - DjangoRedmineAdmin 1.0 released January 8, 2012
    • Symia - Release 0.4 fixes several important bugs December 11, 2011
    • Emerge activity - Version 2.0 released with (optional) Qt interface November 9, 2011
    • Colibri Mailing List Manager - Release of 1.0-beta1 October 12, 2011
    • Mercurial activity extension - Release 2.0 September 18, 2011
    • Python Mesh Viewer - 2.1 released May 13, 2011
    • Convex Processing - Maintenance release : 1.1 is out April 13, 2011
    • Opale - Maintenance release : 1.1 is out March 28, 2011
    • Mercurial activity extension - Release 1.4 January 26, 2011
    • qxv - 0.2 released January 24, 2011
  • 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 © 2012 Bluebird's blog All Rights Reserved XHTML CSS THEME by I SOFTWARE REVIEWS