Recent

Author Topic: Conflict when static linking in external linker  (Read 2751 times)

sollapse

  • New member
  • *
  • Posts: 8
Conflict when static linking in external linker
« on: March 08, 2024, 02:53:09 pm »
I'm attempting to compile an test app using the PortMidi library. I've compiled it statically using TDM64-GCC. When statically linking the library along with the necessary MingW32 libs using the -Xe option, the project compiles and runs normally as a bare bones console app. When I attempt to compile the app including the LCL for GUI, the external linker throws an error while attempting to link an object file from the Windows API it seems. This external linker error also occurs whether statically linking the library or not adding it to the project at all. Why does it error out when linking LCL on Windows? I've included a test project file with all the necessary static libs also.
« Last Edit: March 08, 2024, 10:35:03 pm by Tomas Hajny »

Thaddy

  • Hero Member
  • *****
  • Posts: 15544
  • Censorship about opinions does not belong here.
Re: Conflict when static linking in external linker
« Reply #1 on: March 08, 2024, 07:28:27 pm »
I got a virus warning on the download. Please remove executables, but not the libraries.
(and yes, ms defender can scan 7z in windows 11.)
Can obviously be a false positive.
[edit]
It is a positive. DO NOT DOWNLOAD
I checked it in clean room
« Last Edit: March 08, 2024, 07:48:25 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #2 on: March 08, 2024, 07:46:45 pm »
I actually removed the exe from the file before posting to get within the size limit. It's just the static libraries and project files/source.

Thaddy

  • Hero Member
  • *****
  • Posts: 15544
  • Censorship about opinions does not belong here.
Re: Conflict when static linking in external linker
« Reply #3 on: March 08, 2024, 07:53:46 pm »
I just found out the libraries are not safe. (I am CEH certified) Plz remove all binaries and provide links to where to get them, As is, nobody will download this. (except me, because I have a clean room, Hotel California style: You can enter but never leave, or better Sartre, Huit Clos, where the Eagles stole it from)
« Last Edit: March 08, 2024, 08:04:16 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #4 on: March 08, 2024, 10:32:55 pm »
That's very odd. I just compiled the PortMidi library from the source using the Github master. If I host them on my own Github, it'll be the exact same static's. Can't you just test it in a sandbox environment? The bug is not with static linking PortMidi per se, but linking with the external linker option referencing LCL. It crashes while linking the Windows API object files included with FPC. If you can compile your own test application that links with LCL using the -Xe option, you should see the explicit error(s) I'm speaking of. PortMidi isn't necessary at all to replicate the issue. Are you also able to share your endpoint threat assessment of the files with me for my own reference?

Tomas Hajny

  • Moderator
  • New Member
  • *****
  • Posts: 45
Re: Conflict when static linking in external linker
« Reply #5 on: March 08, 2024, 10:39:16 pm »
Hi,

I removed the attachment to stay on the safe side. Please, provide input containing just sources, not precompiled libraries. If external binary libraries are necessary, reference their original source location (just the source site, not URL of the binary file).

Tomas
(one of forum moderators)

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #6 on: March 08, 2024, 11:00:12 pm »
Will do. I'll copy the project/source file once I get home sans the PortMidi library.

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #7 on: March 11, 2024, 10:30:46 pm »
Sorry for the delay. I've pasted the test code for a basic console app which links LCL, and the project file.

project2.lpi
Code: Pascal  [Select][+][-]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectOptions>
  4.     <Version Value="12"/>
  5.     <PathDelim Value="\"/>
  6.     <General>
  7.       <Flags>
  8.         <MainUnitHasCreateFormStatements Value="False"/>
  9.         <MainUnitHasTitleStatement Value="False"/>
  10.         <MainUnitHasScaledStatement Value="False"/>
  11.       </Flags>
  12.       <SessionStorage Value="InProjectDir"/>
  13.       <Title Value="project2"/>
  14.       <UseAppBundle Value="False"/>
  15.       <ResourceType Value="res"/>
  16.     </General>
  17.     <BuildModes>
  18.       <Item Name="Default" Default="True"/>
  19.     </BuildModes>
  20.     <PublishOptions>
  21.       <Version Value="2"/>
  22.       <UseFileFilters Value="True"/>
  23.     </PublishOptions>
  24.     <RunParams>
  25.       <FormatVersion Value="2"/>
  26.     </RunParams>
  27.     <RequiredPackages>
  28.       <Item>
  29.         <PackageName Value="LCL"/>
  30.       </Item>
  31.       <Item>
  32.         <PackageName Value="LCLBase"/>
  33.       </Item>
  34.     </RequiredPackages>
  35.     <Units>
  36.       <Unit>
  37.         <Filename Value="project2.lpr"/>
  38.         <IsPartOfProject Value="True"/>
  39.       </Unit>
  40.     </Units>
  41.   </ProjectOptions>
  42.   <CompilerOptions>
  43.     <Version Value="11"/>
  44.     <PathDelim Value="\"/>
  45.     <Target>
  46.       <Filename Value="project2"/>
  47.     </Target>
  48.     <SearchPaths>
  49.       <IncludeFiles Value="$(ProjOutDir)"/>
  50.       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
  51.     </SearchPaths>
  52.     <Linking>
  53.       <Debugging>
  54.         <DebugInfoType Value="dsDwarf3"/>
  55.       </Debugging>
  56.       <Options>
  57.         <PassLinkerOptions Value="True"/>
  58.         <LinkerOptions Value="-k -verbose"/>
  59.       </Options>
  60.     </Linking>
  61.     <Other>
  62.       <CustomOptions Value="-Xe"/>
  63.     </Other>
  64.   </CompilerOptions>
  65.   <Debugging>
  66.     <Exceptions>
  67.       <Item>
  68.         <Name Value="EAbort"/>
  69.       </Item>
  70.       <Item>
  71.         <Name Value="ECodetoolError"/>
  72.       </Item>
  73.       <Item>
  74.         <Name Value="EFOpenError"/>
  75.       </Item>
  76.     </Exceptions>
  77.   </Debugging>
  78. </CONFIG>
  79.  

project2.lpr
Code: Pascal  [Select][+][-]
  1. program project2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6. SysUtils, Forms, Interfaces;
  7.  
  8. //{$linklib portmidi}
  9. //{$linklib msvcr120}
  10. //{$linklib kernel32}
  11. //{$linklib winmm}
  12.  
  13.  
  14. //function Pm_CountDevices(): Integer ; cdecl; external;
  15.  
  16. begin
  17. WriteLn('Test');
  18. end.
  19.  
  20.  

project2.lps
Code: Pascal  [Select][+][-]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectSession>
  4.     <PathDelim Value="\"/>
  5.     <Version Value="12"/>
  6.     <BuildModes Active="Default"/>
  7.     <Units>
  8.       <Unit>
  9.         <Filename Value="project2.lpr"/>
  10.         <IsPartOfProject Value="True"/>
  11.         <IsVisibleTab Value="True"/>
  12.         <CursorPos X="15" Y="16"/>
  13.         <UsageCount Value="21"/>
  14.         <Loaded Value="True"/>
  15.       </Unit>
  16.     </Units>
  17.     <JumpHistory HistoryIndex="6">
  18.       <Position>
  19.         <Filename Value="project2.lpr"/>
  20.         <Caret Line="12" Column="9"/>
  21.       </Position>
  22.       <Position>
  23.         <Filename Value="project2.lpr"/>
  24.         <Caret Line="13" Column="43"/>
  25.       </Position>
  26.       <Position>
  27.         <Filename Value="project2.lpr"/>
  28.         <Caret Line="10" Column="3"/>
  29.       </Position>
  30.       <Position>
  31.         <Filename Value="project2.lpr"/>
  32.         <Caret Line="17"/>
  33.       </Position>
  34.       <Position>
  35.         <Filename Value="project2.lpr"/>
  36.         <Caret Line="11"/>
  37.       </Position>
  38.       <Position>
  39.         <Filename Value="project2.lpr"/>
  40.         <Caret Line="10"/>
  41.       </Position>
  42.       <Position>
  43.         <Filename Value="project2.lpr"/>
  44.         <Caret Line="6" Column="28"/>
  45.       </Position>
  46.     </JumpHistory>
  47.     <RunParams>
  48.       <FormatVersion Value="2"/>
  49.       <Modes ActiveMode=""/>
  50.     </RunParams>
  51.   </ProjectSession>
  52.   <Debugging>
  53.     <BreakPoints>
  54.       <Item>
  55.         <Kind Value="bpkSource"/>
  56.         <WatchScope Value="wpsLocal"/>
  57.         <WatchKind Value="wpkWrite"/>
  58.         <Source Value="project2.lpr"/>
  59.         <Line Value="8"/>
  60.       </Item>
  61.     </BreakPoints>
  62.   </Debugging>
  63. </CONFIG>
  64.  

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #8 on: March 13, 2024, 09:07:23 pm »
I've included the output from the compilation. It tends to freeze when importing an object file from the Windows API.

Code: Pascal  [Select][+][-]
  1. (C:\fpcupdeluxe\fpc\units\x86_64-win64\winunits-base\libimpcommctrl.a)impcommctrl1t75.o
  2. attempt to open C:\fpcupdeluxe\fpc\units\x86_64-win64\rtl\libimpdos.a succeeded
  3. attempt to open C:\fpcupdeluxe\lazarus\lcl\units\x86_64-win64\win32\libimpwin32int.a succeeded
  4. attempt to open C:\fpcupdeluxe\lazarus\lcl\units\x86_64-win64\win32\libimpwin32extra.a succeeded
  5. attempt to open C:\fpcupdeluxe\fpc\units\x86_64-C:\fpcupdeluxe\projects\project2\project2.lpr(18,1) Error: (9013) Error while linking
  6. C:\fpcupdeluxe\projects\project2\project2.lpr(18,1) Fatal: (10026) There were 1 errors compiling module, stopping
  7. Fatal: (1018) Compilation aborted
  8. Error: C:\fpcupdeluxe\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode

tetrastes

  • Hero Member
  • *****
  • Posts: 517
Re: Conflict when static linking in external linker
« Reply #9 on: March 18, 2024, 02:15:13 pm »
I've downloaded your .lpi and .lpr and compiled in Lazarus 3.2 without any problem, except an enormous size of the resulting binary.
Just out of curiosity, I've successfully compiled the simplest default one-form GUI project with -Xe option also.

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #10 on: March 18, 2024, 05:43:57 pm »
I've downloaded your .lpi and .lpr and compiled in Lazarus 3.2 without any problem, except an enormous size of the resulting binary.
Just out of curiosity, I've successfully compiled the simplest default one-form GUI project with -Xe option also.

Are you able to say which version of the compiler you're running? I'm using a trunk version compiled with FPCUPDeluxe.

tetrastes

  • Hero Member
  • *****
  • Posts: 517
Re: Conflict when static linking in external linker
« Reply #11 on: March 18, 2024, 07:42:56 pm »
I use stable fpc 3.2.2 installed from official Lazarus distribution https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%203.2/.

tetrastes

  • Hero Member
  • *****
  • Posts: 517
Re: Conflict when static linking in external linker
« Reply #12 on: March 18, 2024, 10:05:28 pm »
It seems that the issue is related to Lazarus version. With Lazarus 2.2.2 fpc 3.2.2 I get similar error.

sollapse

  • New member
  • *
  • Posts: 8
Re: Conflict when static linking in external linker
« Reply #13 on: March 22, 2024, 04:18:04 pm »
It seems that the issue is related to Lazarus version. With Lazarus 2.2.2 fpc 3.2.2 I get similar error.

I've recompiled FPC and Lazarus from the latest trunk versions under Gitlab and it seems that static linking works correctly with the internal linker now. The external linker still fails with LCL, but the internal one will work fine for my needs.

 

TinyPortal © 2005-2018