[SOLVED] How to get rid of linker option --gc-sections lazarus / 34-Windows ---------------------------------------------------------------------- Nevada Smith · 2022-05-16 05:06 I am trying to statically link portaudio in Windows. I am using the libportaudio.a file obtained through MSYS2. I had to jump through a few hoops, but I am there, I think, almost. Please note that I have specified -Xe option to use external linker. The linker runs with the below options, but errors out, without any specific message. It exits with a non-zero return code (%ERRORLEVEL%) and the executable generate has a size of 0 bytes. ld.exe -b pei-x86-64  --gc-sections  -s --subsystem windows --entry=_WinMainCRTStartup    -o D:\pdev\fpc\g_catbell\vc\src\catbell.exe D:\pdev\fpc\g_catbell\vc\src\link.res However, I have been able to link it successfully if I omit the flag --gc-sections. The executable although not extensively tested, appears to run fine. I tried to use add --no-gc-sections through Project Options > Compilation and Linknig > Pass options to linker with "-k" option, but the command-line ends up having both --no-gc-sections and --gc- sections, in that order, and the latter overrides the former (I think). Is there any way to get the flag --gc-sections omitted or overridden through the IDE?  Or at least through lazbuild? ---------------------------------------------------------------------- Thaddy · 2022-05-16 05:52 For the external linker, a linker script can be  created, so maybe you should edit that? Usually not recommended. (-s option) https://www.freepascal.org/docs-html/current/user/usersu71.html https://www.freepascal.org/docs- html/current/user/usersu15.html#x38-450005.1.4 ---------------------------------------------------------------------- marcov · 2022-05-16 07:35 Disable smart linking.  (-XX) ---------------------------------------------------------------------- Nevada Smith · 2022-05-18 18:48 Adding -s (-sh) to Custom options worked. It created a ppas.bat and stopped. I could then perform the actual linking on my own.