Recent

Author Topic: Non-OS dependent way to use fpcres, the FPC resource file converter  (Read 2162 times)

Kepsz

  • New Member
  • *
  • Posts: 32
I recently found out that Lazarus contains its own resource converter, so it is no longer necessary to use the old brcc32 compiler, which disappeared from the net and only worked under Windows anyway...
However, I did not find any substantial documentation on its use.


Let see the usage under Windows.

Right now, the first option is to set the file path manually to the pre-compile command, but that will only work till the next Lazarus update. Same is true to adding the ..fpc\3.2.2\bin folder to $PATH.
Code: Pascal  [Select][+][-]
  1. D:\Work\Lazarus\fpc\3.2.2\bin\x86_64-win64\fpcres.exe resfile.rc -o resfile.res -of res

The second option is to upgrade that line with IDE macros:
Code: Pascal  [Select][+][-]
  1. $(LazarusDir)\fpc\$(FPCVER)\bin\$(TargetCPU)-$(TargetOS)\fpcres.exe resfile.rc -o resfile.res -of res


Option 2 works fine... However, it is not Linux compatible. Under Linux, the entire file browsing process is unnecessary, because the OS already knows the location of the fpcres program by default.
A universal solution for this would be nice, because I sometimes work on the same project from both Linux and Windows using GIT.

paweld

  • Hero Member
  • *****
  • Posts: 1250
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #1 on: February 16, 2024, 01:24:07 pm »
if you are using rc file then you don't need to convert to res file yourself, when building a project Lazarus will do it automatically. You just attach only the rc file:
Code: Pascal  [Select][+][-]
  1. {$R my_resources.rc}
Best regards / Pozdrawiam
paweld

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11868
  • FPC developer.
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #2 on: February 16, 2024, 01:29:32 pm »
Just put it in your .dpr/.lpr like this:

Code: Pascal  [Select][+][-]
  1. {$R 'logo.res' 'logo.rc'}

and FPC should auto call the resource compiler.

Note that fpcres is still not the default for third party resource scripts, the current defaults are windres (for 32-bit) or gorc32 for 64-bit resource files.

It is mostly included for testing purposes. When it becomes default the compiler will directly call it.

p.s. brccc32 was never a recommended or supported tool for FPC/Lazarus.

Thaddy

  • Hero Member
  • *****
  • Posts: 16030
  • Censorship about opinions does not belong here.
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #3 on: February 16, 2024, 05:48:14 pm »
Marco is right, with the provision that if you change the resource you *must* rebuild your project, otherwise the compiler/linker will use the old resource. The feature Marco described is Delphi compatible, btw.
If I smell bad code it usually is bad code and that includes my own code.

Kepsz

  • New Member
  • *
  • Posts: 32
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #4 on: February 17, 2024, 03:01:12 pm »
Just put it in your .dpr/.lpr like this:

Code: Pascal  [Select][+][-]
  1. {$R 'logo.res' 'logo.rc'}

and FPC should auto call the resource compiler.

Note that fpcres is still not the default for third party resource scripts, the current defaults are windres (for 32-bit) or gorc32 for 64-bit resource files.

It is mostly included for testing purposes. When it becomes default the compiler will directly call it.

p.s. brccc32 was never a recommended or supported tool for FPC/Lazarus.


Thank you (all) for the suggestions.
On Windows10 x64, I tried this:

{$R resfile.rc} in the .lpr file.
It works, but it tries to use windres instead of gorc, and windres will nor work on 64 bit. I did not installed gorc manualy, but I would like to have some non-OS dependent solution.

So I tried to use fpcres by adding this to fpc.cfg (from https://wiki.lazarus.freepascal.org/Lazarus_Resources):

# Use fpcres as resource compiler
-FF

But the fpc 3.3.2 does not understand the -FF switch.

Thaddy

  • Hero Member
  • *****
  • Posts: 16030
  • Censorship about opinions does not belong here.
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #5 on: February 17, 2024, 03:06:28 pm »
How can you miss Marco's answer?
Code: Pascal  [Select][+][-]
  1. {$R 'logo.res' 'logo.rc'}
Nothing more, nothing less.
And a rebuild is required, not a recompile, for your project.
And not just the rc... Follow the syntax. <sigh>
Only a rebuild will call any resource compiler to create a res file. Which one does not matter. It is completely cross platform and FPC will install a proper resource compiler when it is installed itself.
You are barking up the wrong tree. Do what you are told.
Nowadays it will install fpcres...which is cross platform. (Thanks to the same Marco)
« Last Edit: February 17, 2024, 03:33:30 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Kepsz

  • New Member
  • *
  • Posts: 32
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #6 on: February 17, 2024, 04:14:48 pm »
How can you miss Marco's answer?
Code: Pascal  [Select][+][-]
  1. {$R 'logo.res' 'logo.rc'}
Nothing more, nothing less.
And a rebuild is required, not a recompile, for your project.
And not just the rc... Follow the syntax. <sigh>
Only a rebuild will call any resource compiler to create a res file. Which one does not matter. It is completely cross platform and FPC will install a proper resource compiler when it is installed itself.
You are barking up the wrong tree. Do what you are told.
Nowadays it will install fpcres...which is cross platform. (Thanks to the same Marco)

Okay, I'm trying... But is the file order okay?

Code: Pascal  [Select][+][-]
  1. {$R 'resfile.res' 'resfile.rc'}
If I use this, then it will fail, because the resource.res file is not yet there. (If I have a resfile.res already there, then this will not update it)

Code: Pascal  [Select][+][-]
  1. {$R 'resfile.rc' 'resfile.res'}
If I use this, than it tries to use windres on x64 target to create resfile.res, but that is not working.

paweld

  • Hero Member
  • *****
  • Posts: 1250
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #7 on: February 17, 2024, 04:35:19 pm »
As I wrote above, just add to the code:
Code: Pascal  [Select][+][-]
  1. {$R my_resources.rc}  
works well for x86 and x64 targets
Best regards / Pozdrawiam
paweld

Thaddy

  • Hero Member
  • *****
  • Posts: 16030
  • Censorship about opinions does not belong here.
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #8 on: February 17, 2024, 05:02:44 pm »
As I wrote above, just add to the code:
Code: Pascal  [Select][+][-]
  1. {$R my_resources.rc}  
works well for x86 and x64 targets
That should not be allowed, at least not in mode delphi, because in Delphi it is allowed to create a resource with a different name as the rc script. It is a welcome feature, though except I did not know it. Note my remark: a rebuild is still necessary.
If I smell bad code it usually is bad code and that includes my own code.

paweld

  • Hero Member
  • *****
  • Posts: 1250
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #9 on: February 17, 2024, 06:40:49 pm »
Quote from: Thaddy
That should not be allowed, at least not in mode delphi, because in Delphi it is allowed to create a resource with a different name as the rc script.
I mainly use the objfpc mode and this solution works well, and the OP did not mention anything about the delphi mode.
Quote
Note my remark: a rebuild is still necessary.
The rebuild itself unfortunately doesn't work for me, if the content of the files defined in the rc changes - I have to do clean and build.
Best regards / Pozdrawiam
paweld

Kepsz

  • New Member
  • *
  • Posts: 32
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #10 on: February 18, 2024, 02:18:39 pm »
Code: Pascal  [Select][+][-]
  1. {$R 'resfile.rc' 'resfile.res'}

Now I know what's the problem. This will only work, if there is no space in the project folder name. If there is a space in the name, then the build will fail when it reaches the resource convert part.
For example, "Program2" folder name is good but "Program 2" is not.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5738
  • Compiler Developer
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #11 on: February 18, 2024, 02:26:59 pm »
Code: Pascal  [Select][+][-]
  1. {$R 'resfile.rc' 'resfile.res'}

Now I know what's the problem. This will only work, if there is no space in the project folder name. If there is a space in the name, then the build will fail when it reaches the resource convert part.
For example, "Program2" folder name is good but "Program 2" is not.

And that's why we want to move to fpcres instead of windres and gorc, because fpcres doesn't have this restriction.

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Non-OS dependent way to use fpcres, the FPC resource file converter
« Reply #12 on: September 17, 2024, 05:27:57 pm »
How can you miss Marco's answer?
Code: Pascal  [Select][+][-]
  1. {$R 'logo.res' 'logo.rc'}
Nothing more, nothing less.
And a rebuild is required, not a recompile, for your project.
And not just the rc... Follow the syntax. <sigh>
Only a rebuild will call any resource compiler to create a res file. Which one does not matter. It is completely cross platform and FPC will install a proper resource compiler when it is installed itself.
You are barking up the wrong tree. Do what you are told.
Nowadays it will install fpcres...which is cross platform. (Thanks to the same Marco)

* Mac Mini M1 (silicon)
* macOS 14.6.1 Sonoma
* Lazarus 3.4
* FPC 3.2.2

Is this supposed to work in Lazarus 3.4 / FPC 3.2.2 running under macOS 14.6.1?

I have the file 'OsmosePresets.txt' which contains text in the form...
Code: Text  [Select][+][-]
  1. bass
  2. 30, 1, "acid bass", "aggressive + analog + distorted + stereo"
  3. 30, 2, "acouskop", "acoustic + distorted + fm + shaking"
  4. 30, 31, "bass distosine", "acoustic + synthetic"
  5. 30, 32, "bass monster", "analog + distorted + portamento + synthetic"
  6. 30, 74, "chordead", "analog + chords"
  7. 30, 108, "deep corners", "analog + chords"
  8. 30, 112, "dirt acid", "analog + distorted"
  9. 30, 119, "doubleslap", "acoustic + shaking + warm + woody"
  10. 30, 127, "edgy fm", "fm"
  11. 31, 3, "eighty neon", "analog"
  12. 31, 5, "electric bass 1", "acoustic + electric"
  13. 31, 6, "electric bass 2", "acoustic + electric"
  14. 31, 29, "fat model d", "analog + big + noise + portamento + warm"
  15. 31, 36, "flunkly", "analog"
  16. 31, 43, "fm darkness", "aggressive + big + dark + digital + dry + ensemble + fm + noise"
  17. 31, 44, "fm doublebass", "clean + fm + portamento"
  18. 31, 50, "fm slapman", "bright + digital + fm + metallic + stereo"
  19. 31, 54, "forgotten animal", "analog + fm + portamento"
  20. 31, 55, "forty eight db", "analog + distorted"
  21. 31, 56, "fourad", "analog + distorted"
  22. 31, 57, "fretless bass", "acoustic + portamento"
  23. 31, 76, "grittysaw", "analog + distorted"
  24. 31, 86, "hollowrez", "analog"
  25. 31, 107, "juknow that bass", "analog + big + clean + simple + soft + stereo"
  26. 31, 121, "kinespeech", "analog + vocal"
  27. 32, 5, "lacous bass", "acoustic + portamento"
  28. 32, 7, "ladder bass", "analog + lfo + synthetic"
  29. 32, 58, "night bass", "analog + portamento"
  30. 32, 92, "outspoken", "analog"
  31. 32, 109, "piercing bass", "aggressive + big + dark + digital"
  32. 32, 114, "pl-bass", "analog + dry + warm"
  33. 32, 126, "pulzz", "analog"
  34. 33, 5, "reesotto", "aggressive + digital"
  35. 33, 6, "reesy rider", "aggressive + analog + distorted + stereo"
  36. 33, 19, "rusty bass", "dark + digital + fm + soft"
  37. 33, 20, "rusty square", "analog + distorted"
  38. 33, 39, "simpledecay", "analog + distorted"
  39. 33, 41, "simplerez", "analog"
  40. 33, 48, "smooth operator", "acoustic + fm"
  41. 33, 49, "solid square", "analog"
  42. 33, 68, "steroids", "analog + noise"
  43. 33, 74, "sub bass 1", "analog"
  44. 33, 75, "subway", "analog + clean + dark + fm + simple"
  45. 33, 77, "syncat", "analog"
  46. 33, 95, "thrilla bass", "analog + dry"
  47. 33, 114, "velsquare", "analog"
  48. 33, 119, "vintage wide bass", "analog + big + dark + portamento + soft + stereo + warm"
  49. 33, 125, "walking blues", "acoustic"
  50. 33, 127, "wallface", "digital + fm + portamento"
  51. bowed
  52. 30, 20, "archer", "acoustic"
  53. 30, 51, "bowreal lights", "acoustic + layered + reverberant"
  54. 30, 66, "cellove", "acoustic + portamento"
  55. 30, 67, "cellovir", "acoustic"
  56. 30, 68, "chamber mellobow", "acoustic + ensemble + lofi + stereo"
  57. 30, 69, "chamber strings", "acoustic + clean + ensemble"
  58. 30, 120, "duocello", "acoustic + portamento"
  59. 31, 22, "erumi", "acoustic"
  60. 31, 82, "harmod", "acoustic + portamento"
  61. 31, 92, "hybrid strings 1", "analog"
  62. 31, 93, "hybrid strings 2", "analog + lofi + noise"
  63. 31, 94, "hybrid strings 3", "acoustic + analog"
  64. 32, 27, "lost ensemble", "acoustic + analog + reverberant"
  65. 32, 61, "noisyman", "acoustic"
  66. 32, 62, "noisypad", "acoustic + noise"
  67. 32, 67, "numens strings", "acoustic"
  68. 32, 98, "pajestric", "layered"
  69. 32, 104, "pcs dandelion", "bright + echo + evolving + icy + portamento + synthetic"
  70. 32, 123, "pressow", "acoustic"
  71. 33, 18, "roto string", "acoustic + airy + lfo + noise"
  72. 33, 24, "scie tard", "acoustic + portamento"
  73. 33, 73, "stringtroen", "acoustic"
  74. 33, 101, "trepizcato", "acoustic"
  75. 33, 120, "viollaggio", "acoustic"
  76. 33, 121, "violloiv", "acoustic + echo"
  77. 33, 122, "vln vla cel bass 2", "acoustic + clean"
  78.  

but there's a lot more of it!

I have the file 'OsmosePresets.rc' which simply contains...
Code: Text  [Select][+][-]
  1. OsmosePresets RCDATA OsmosePresets.txt
  2.  

In my code, I have...
Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. {$R 'OsmosePresets.res' 'OsmosePresets.rc'}
  4.  

which I'm sure you'll agree follows the same pattern as Marco's answer!

When I build the project, which is called 'OsmosePresets.lpi', a new 'OsmosePresets.res' is generated but the project fails to build.

Also I get the following errors after the attempt to build...
Code: Text  [Select][+][-]
  1. Error: Duplicate resource: Type = 24, Name = 1, Lang ID = 0000
  2. Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates.
  3.  

I've spent a day and a half on this issue and I cannot help thinking that it should not be this difficult. I'm not a newbie, having a career in Delphi that dates back to 1995, but this is getting the better of me.

Any help would be really appreciated  ;)
"It builds... ship it!"

 

TinyPortal © 2005-2018