Author Topic: Possible Bug - Passing Environment Variables to Resource File  (Read 2244 times)

Offline Tempris

  • Single posting newcomer
  • *
  • Posts: 2
Possible Bug - Passing Environment Variables to Resource buildCommand with option '-m64'

I am having some trouble figuring out why I cannot seem to get Code::Blocks to pass my environment variables to my resource file build commands when compiling targeting a 64 bit exe.
I have 2 environment variables defined in each target that are meant to be passed to the resource file, WINDRES_DEFINE and WINDRES_TARGET. 32 bit builds using the MinGW 32 bit that comes with Code::Blocks works fine as they get passed, but when I compile the 64bit targets they show up as a blank space.
My environment variable for each target is shown below:

Code
// Main exe env vars:
<Environment>
  <Variable name="WINDRES_DEFINE" value="" />
  <Variable name="WINDRES_TARGET" value="pe-i386" />
</Environment>
<Environment>
  <Variable name="WINDRES_DEFINE" value="" />
  <Variable name="WINDRES_TARGET" value="pe-x86-64" />
</Environment>

// Server exe env vars:
<Environment>
  <Variable name="WINDRES_DEFINE" value="-DSTANDALONE" />
  <Variable name="WINDRES_TARGET" value="pe-i386" />
</Environment>
<Environment>
  <Variable name="WINDRES_DEFINE" value="-DSTANDALONE" />
  <Variable name="WINDRES_TARGET" value="pe-x86-64" />
</Environment>

// Master Server exe env vars:
<Environment>
  <Variable name="WINDRES_DEFINE" value="-DMASTER -DSTANDALONE" />
  <Variable name="WINDRES_TARGET" value="pe-i386" />
</Environment>
<Environment>
  <Variable name="WINDRES_DEFINE" value="-DMASTER -DSTANDALONE" />
  <Variable name="WINDRES_TARGET" value="pe-x86-64" />
</Environment>

My resource file is configured as follows:

Code
// Resource File in cbp:
<Unit filename="../../projects/novafide/resources/project.rc">
  <Option compilerVar="WINDRES" />
  <Option compiler="gcc" use="1" buildCommand="$rescomp -F $WINDRES_TARGET $WINDRES_DEFINE -i $file -J rc -o $resource_output -O coff $res_includes" />
  <Option target="main-32bit" />
  <Option target="main-64bit" />
  <Option target="server-32bit" />
  <Option target="server-64bit" />
  <Option target="master-32bit" />
  <Option target="master-64bit" />
</Unit>

To get an idea of the issue I am having I am providing the lines for the windres.exe of each target below.

Code
// .res Build Log Output for 32 bit (pe-i386) builds:

(main.exe) windres.exe -F pe-i386  -i "G:\Cure Interactive\Projects\Video Games\Logic Game Engine\logicgameengine\src\projects\novafide\resources\project.rc" -J rc -o .objs\novafide\main-32bit\projects\novafide\resources\project.rc.res -O coff
(server.exe) windres.exe -F pe-i386 -DSTANDALONE -i "G:\Cure Interactive\Projects\Video Games\Logic Game Engine\logicgameengine\src\projects\novafide\resources\project.rc" -J rc -o .objs\novafide\server-32bit\projects\novafide\resources\project.rc.res -O coff
(master.exe) windres.exe -F pe-i386 -DMASTER -DSTANDALONE -i "G:\Cure Interactive\Projects\Video Games\Logic Game Engine\logicgameengine\src\projects\novafide\resources\project.rc" -J rc -o .objs\novafide\master-32bit\projects\novafide\resources\project.rc.res -O coff

// .res Build Log Output for 64 bit (pe-x86-64) builds:

(main.exe) windres.exe   -J rc -O coff -i "G:\Cure Interactive\Projects\Video Games\Logic Game Engine\logicgameengine\src\projects\novafide\resources\project.rc" -o .objs\novafide\main-64bit\projects\novafide\resources\project.rc.res
(server.exe) windres.exe   -J rc -O coff -i "G:\Cure Interactive\Projects\Video Games\Logic Game Engine\logicgameengine\src\projects\novafide\resources\project.rc" -o .objs\novafide\server-64bit\projects\novafide\resources\project.rc.res
(master.exe) windres.exe   -J rc -O coff -i "G:\Cure Interactive\Projects\Video Games\Logic Game Engine\logicgameengine\src\projects\novafide\resources\project.rc" -o .objs\novafide\master-64bit\projects\novafide\resources\project.rc.res

As you can see "-DSTANDALONE" and "-DMASTER -DSTANDALONE" are missing from the resource file build commands in the 64 bit builds. Is this a bug, a feature, or did I write the build command incorrectly? At this time I am not certain.

It is worth noting that I used TGM-GCC-64 as my compiler in the affected builds, and also that when using a different compiler (MinGW64) I also got this issue.
The projects compile fine, exept that some define dependant options in my resource file do not display the correct information in the properties of the EXE files.

To test some things I decided to take a 64-bit project and cnage the options to build it in 32-bit using the same compiler. Of course this failed to build but I got the variables passed to the resource file! This lends me to beleive this a Code::Blocks issue rather than a compiler issue.

Does Code::Blocks not allow variable passing of this type for third party compilers? I still wonder if I formatted my build command incorrectly. Any help would be very welcome!

I'll attach the full cbp file so that if anyone wants to see the full file they can. I tried to include all the important information but I know sometimes theres never enough info.

I did try to google this issue and spent over a week every day trying to find an answer but I might be the first to experience this problem, not sure.

Offline Tempris

  • Single posting newcomer
  • *
  • Posts: 2
Re: Possible Bug - Passing Environment Variables to Resource File
« Reply #1 on: March 27, 2017, 05:13:06 am »
I apologize for my newbie-ness to this whole issue. While I was investigating the way I defined the resource file I noticed that it has a compiler setting of "gcc". Sure enough, by going into the property options of the .rc file and looking at advanced, I found that each compiler needs its own custom command. I duplicated the buildCommand and got what I would have done manually:

Code
<Unit filename="../../projects/novafide/resources/project.rc">
<Option compilerVar="WINDRES" />
<Option compiler="gcc" use="1" buildCommand="$rescomp -F $WINDRES_TARGET $WINDRES_DEFINE -i $file -J rc -o $resource_output -O coff $res_includes" />
<Option compiler="tdm-gcc-64" use="1" buildCommand="$rescomp -F $WINDRES_TARGET $WINDRES_DEFINE -i $file -J rc -o $resource_output -O coff $res_includes" />
<Option target="main-32bit" />
<Option target="main-64bit" />
<Option target="server-32bit" />
<Option target="server-64bit" />
<Option target="master-32bit" />
<Option target="master-64bit" />
</Unit>

Bingo! It works for all targets now. I cannot believe I overlooked something so simple! (You mean like a semi-colon? Yes, just like a semi-colon, only not..) I swear I spent probably 50 hours researching constantly for a week just to now realize what the issue was. Anyways if I never posted I probably would have still been stuck. Sometimes you need something to throw stuff off of and get yourself thinking.

Should I take this post down? Or would it possibly be useful to others? Apologies again for cluttering up the forums!