Recent

Author Topic: FPC 3.3.1 for AVR – compilation error on Windows 7  (Read 213 times)

ackarwow

  • Full Member
  • ***
  • Posts: 141
    • Andrzej Karwowski's Homepage
FPC 3.3.1 for AVR – compilation error on Windows 7
« on: March 09, 2025, 07:58:29 am »
I am using FPC 3.3.1 compiled for AVRs (sources from october 2024, not very old), and in some specific cases (on Win 7, 64-bit, program source file must be located in path containing space(s)) the compiler returns error – „could not open elf file”.

Execution path (many definitions starting with -d are not important here):

Code: Text  [Select][+][-]
  1. "C:\Program Files\AVRPascal\bin\win64\pp.exe" -n "-FuC:\Program Files\AVRPascal\lib\avr" "-FuC:\Program Files\AVRPascal\lib" "-FUC:\Program Files\AVRPascal\out" -Tembedded -Sg -Si -a -al -gw2 -B -va -vi -vw -vn -vh -O3 -CpAVR5 -WpATMEGA328P -XPavr- -Sm -dATMEGA328P -dAVR5 -dFAMILYMEGA -dF_CPU:=16000000 -dAVRPASCAL -dAVRPASCAL_VERSION:=3 -dAVRPASCAL_RELEASE:=1 -dAVRPASCAL_PATH:=0 -dAVRPASCAL_BUILD:=2429 -dAVRPASCAL_FULLVERSION:=30100 "C:\Program Files\AVRPascal\examples\TestBlink.pas"
  2.  

Compiler output:

Code: Text  [Select][+][-]
  1. (...)
  2. [0.922] Searching file C:\Program Files\AVRPascal\bin\win64\avr-ld.exe... found
  3. [0.922] Using util C:\Program Files\AVRPascal\bin\win64\avr-ld.exe
  4. [0.922] Executing "C:\Program Files\AVRPascal\bin\win64\avr-ld.exe" with command line "-g     --gc-sections   -L. -o "C:\Program Files\AVRPascal\examples\TestBlink.elf" -T link2792.res"
  5. [0.969] TestBlink.pas(27) Fatal: Can't open executable "C:\Program Files\AVRPascal\examples\TestBlink.elf"
  6. [0.969] Fatal: Compilation aborted
  7.  

On Win 10 it works perfectly without errors. I analyzed sources of the compiler and it seems to me that problem is related to quotes in the path. It is a bit strange, but in t_embed.pas TlinkerEmbedded.MakeExecutable method, the filename passed to PostProcessExecutable should not contain quotes. When I made the following changes (highlighted) everything seem to work:

Code: Pascal  [Select][+][-]
  1. function TlinkerEmbedded.MakeExecutable:boolean;
  2. var
  3.   binstr,
  4.   cmdstr,
  5.   mapstr: TCmdStr;
  6.   success : boolean;
  7.   StaticStr,
  8.   GCSectionsStr,
  9.   DynLinkStr,
  10.   StripStr,
  11.   ElfStr, //added by @ackarwow
  12.   FixedExeFileName: string;
  13. begin
  14.   { for future use }
  15.   StaticStr:='';
  16.   StripStr:='';
  17.   mapstr:='';
  18.   DynLinkStr:='';
  19.   ElfStr:=ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf'));//changed by @ackarwow
  20.   FixedExeFileName:=maybequoted(ElfStr);//changed by @ackarwow
  21.  
  22.   GCSectionsStr:='--gc-sections';
  23.   //if not(cs_link_extern in current_settings.globalswitches) then
  24.   if not(cs_link_nolink in current_settings.globalswitches) then
  25.    Message1(exec_i_linking,current_module.exefilename);
  26.  
  27.   if (cs_link_map in current_settings.globalswitches) then
  28.    mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  29.  
  30. { Write used files and libraries }
  31.   WriteResponseFile();
  32.  
  33. { Call linker }
  34.   SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  35.   Replace(cmdstr,'$OPT',Info.ExtraOptions);
  36.   if not(cs_link_on_target in current_settings.globalswitches) then
  37.    begin
  38.     Replace(cmdstr,'$EXE',FixedExeFileName);
  39.     Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  40.     Replace(cmdstr,'$STATIC',StaticStr);
  41.     Replace(cmdstr,'$STRIP',StripStr);
  42.     Replace(cmdstr,'$MAP',mapstr);
  43.     Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  44.     Replace(cmdstr,'$DYNLINK',DynLinkStr);
  45.    end
  46.   else
  47.    begin
  48.     Replace(cmdstr,'$EXE',FixedExeFileName);
  49.     Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  50.     Replace(cmdstr,'$STATIC',StaticStr);
  51.     Replace(cmdstr,'$STRIP',StripStr);
  52.     Replace(cmdstr,'$MAP',mapstr);
  53.     Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  54.     Replace(cmdstr,'$DYNLINK',DynLinkStr);
  55.    end;
  56.   success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  57.  
  58. { Remove ReponseFile }
  59.   if success and not(cs_link_nolink in current_settings.globalswitches) then
  60.    DeleteFile(outputexedir+Info.ResName);
  61.  
  62. { Post process }
  63.   if success and not(cs_link_nolink in current_settings.globalswitches) then
  64.     success:=PostProcessExecutable(ElfStr,false);//changed by @ackarwow
  65.  
  66.   if success and (target_info.system in [system_arm_embedded,system_avr_embedded,system_mipsel_embedded,system_xtensa_embedded]) then
  67.     begin
  68.       success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O ihex '+
  69.         FixedExeFileName+' '+
  70.         maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.hex'))),true,false);
  71.       if success then
  72.         success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  73.           FixedExeFileName+' '+
  74.           maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  75.         if success and (target_info.system in systems_support_uf2) and (cs_generate_uf2 in current_settings.globalswitches) then
  76.           success := GenerateUF2(maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),
  77.                                  maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.uf2'))),
  78.                                  embedded_controllers[current_settings.controllertype].flashbase);
  79. {$ifdef ARM}
  80.       if success and (current_settings.controllertype = ct_raspi2) then
  81.         success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+ FixedExeFileName + ' kernel7.img',true,false);
  82. {$endif ARM}
  83.     end;
  84.  
  85.   MakeExecutable:=success;   { otherwise a recursive call to link method }
  86. end;
  87.  

Did you have similar problems, or do you have better solution? Or maybe I made a mistake somwhere…?

Edit: To reproduce this - try to compile any file on a path containing space(s) on Windows 7
« Last Edit: March 09, 2025, 08:47:52 am by ackarwow »

 

TinyPortal © 2005-2018