Author Topic: Opening a project ignores duplicated linker options  (Read 3149 times)

Offline Mr_KoKa

  • Single posting newcomer
  • *
  • Posts: 2
Opening a project ignores duplicated linker options
« on: March 04, 2023, 04:25:39 am »
When opening a project with target like this (please notice duplicated -lcrypto and -lssl)

Code
<Target title="Release">
<Option output="bin/Release/Project" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="0" />
<Option compiler="msys2_mingw32" />
<Compiler>
<Add option="-O2" />
<Add option="-Wextra" />
<Add option="-std=c++11" />
<Add option="-Wno-unused-parameter" />
<Add option="-DCURL_STATICLIB" />
<Add directory="C:/curl-7.88.1/include" />
<Add directory="include" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-static" />
<Add option="c:\curl-7.88.1\lib\.libs\libcurl.a" />
<Add option="-DCURL_STATICLIB" />
<Add option="-lgdiplus" />
<Add option="-lcomctl32" />
<Add option="-lgdi32" />
<Add option="-lbcrypt" />
<Add option="-lcrypto" />
<Add option="-lssl" />
<Add option="-lcrypto" />
<Add option="-lssl" />
<Add option="-lzstd" />
<Add option="-lz" />
<Add option="-lwldap32" />
<Add option="-lcrypt32" />
<Add option="-lws2_32" />
</Linker>
</Target>

Result is:



So the duplicated linked options are ignored. Project does not compile without them.

Name             : Code::Blocks
Version          : 20.03-r11983
SDK Version      : 2.0.0
Scintilla Version: 3.7.5
Author           : The Code::Blocks Team
E-mail           : info@codeblocks.org
Website          : http://www.codeblocks.org

wxWidgets Library (wxMSW port)
Version 3.1.3 (Unicode: wchar_t, debug level: 1),
compiled at Nov  1 2019 18:53:26

Runtime version of toolkit used is 10.0.
« Last Edit: March 09, 2023, 11:57:00 pm by Mr_KoKa »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7666
    • My Best Post
Re: Opening a project ignores duplicated linker options
« Reply #1 on: March 05, 2023, 01:14:34 am »
I would suggest putting the libraries in the link library list and see if that works.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Mr_KoKa

  • Single posting newcomer
  • *
  • Posts: 2
Re: Opening a project ignores duplicated linker options
« Reply #2 on: March 05, 2023, 08:01:20 pm »
It does not work either. After opening project with target linker section as such:
Code
<Linker>
<Add option="-s" />
<Add option="-static" />
<Add library="c:/curl-7.88.1/lib/.libs/libcurl.a" />
<Add library="libgdiplus.a" />
<Add library="libcomctl32.a" />
<Add library="libgdi32.a" />
<Add library="libbcrypt.a" />
<Add library="libcrypto.a" />
<Add library="libssl.a" />
<Add library="libzstd.a" />
<Add library="libz.a" />
<Add library="libwldap32.a" />
<Add library="libcrypt32.a" />
<Add library="libws2_32.a" />
<Add library="libcrypto.a" />
<Add library="libssl.a" />
<Add directory="C:/msys64/mingw32/lib" />
</Linker>
Result is:


It works until restart.

But as I wrote this post I thought about solution to mklink these 2 libraries I need duplicated to different location and add them full path second time and it works, does not remove as duplicate.

The linker section look now like this:
Code
<Linker>				
<Add option="-s" />
<Add option="-static" />
<Add library="c:/curl-7.88.1/lib/.libs/libcurl.a" />
<Add library="libgdiplus.a" />
<Add library="libmsimg32.a" />
<Add library="libbcrypt.a" />
<Add library="libcrypto.a" />
<Add library="libssl.a" />
<Add library="C:/libdup/libcrypto.a" />
<Add library="C:/libdup/libssl.a" />
<Add library="libzstd.a" />
<Add library="libz.a" />
<Add library="libwldap32.a" />
<Add library="libcrypt32.a" />
<Add library="libws2_32.a" />
<Add directory="C:/msys64/mingw32/lib" />
</Linker>

BTW when adding library path to linker search path and entering them by filename without full path they become linker options instead in build log, only libraries added by full path appear as files in build log, so maybe adding them all as full path would work, or maybe it would still be seen as duplicate and would be removed.
Code
-s -static  -lgdi32 -luser32 -lkernel32 -lcomctl32 c:\curl-7.88.1\lib\.libs\libcurl.a -lgdiplus -lmsimg32 -lbcrypt -lcrypto -lssl C:\libdup\libcrypto.a C:\libdup\libssl.a -lzstd -lz -lwldap32 -lcrypt32 -lws2_32 -mwindows

Thanks for the idea for the workaround :]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7666
    • My Best Post
Re: Opening a project ignores duplicated linker options
« Reply #3 on: March 05, 2023, 10:54:42 pm »
Example: gdiplus should be added to linker library list if you wish to link to shared gdiplus.
If you wish to link to static library then use full library paths work for me.

Edit: IIRC, using "libgdiplus.a" tells the compiler to link to static version of gdiplus for some Compilers.

Tim S.

« Last Edit: March 05, 2023, 11:01:13 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org