Linker fails to find libraries

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Forthro
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Jun 06, 2023 11:58 am

Linker fails to find libraries

Post by Forthro »

I'm trying to build wxWidgets project on Ubuntu 22 with CLion using CMake.
I've installed a pre-compiled version of wxWidgets by following these instructions: https://docs.codelite.org/wxWidgets/rep ... and-debian
My CMakeLists includes the following lines, as stated in: https://docs.wxwidgets.org/3.2/overview ... cmake_apps

Code: Select all

find_package(wxWidgets REQUIRED COMPONENTS gl net core base)
if (wxWidgets_USE_FILE) # not defined in CONFIG mode
    include(${wxWidgets_USE_FILE})
endif ()
and

Code: Select all

target_link_libraries(%my target% ${wxWidgets_LIBRARIES})
CMake and compilation run successfully, but during the linking stage I get the following errors:
/usr/bin/ld: cannot find -lwx_gtk3u_unofficial_gl-3.2: No such file or directory
/usr/bin/ld: cannot find -lwx_baseu_unofficial_net-3.2: No such file or directory
/usr/bin/ld: cannot find -lwx_gtk3u_unofficial_core-3.2: No such file or directory
/usr/bin/ld: cannot find -lwx_baseu_unofficial-3.2: No such file or directory
Why are these libraries missing and where can I get them?
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Linker fails to find libraries

Post by DavidHart »

Hi,

What is the result of doing, in a terminal:
wx-config --libs all
Mine is:

Code: Select all

david@vbox:/common/Repositories/ubuntu$ wx-config --libs all
-L/usr/lib/x86_64-linux-gnu -pthread   -lwx_gtk3u_unofficial_xrc-3.2 -lwx_gtk3u_unofficial_webview-3.2 -lwx_gtk3u_unofficial_stc-3.2 -lwx_gtk3u_unofficial_richtext-3.2 -lwx_gtk3u_unofficial_ribbon-3.2 -lwx_gtk3u_unofficial_propgrid-3.2 -lwx_gtk3u_unofficial_aui-3.2 -lwx_gtk3u_unofficial_gl-3.2 -lwx_gtk3u_unofficial_media-3.2 -lwx_gtk3u_unofficial_html-3.2 -lwx_gtk3u_unofficial_qa-3.2 -lwx_gtk3u_unofficial_core-3.2 -lwx_baseu_unofficial_xml-3.2 -lwx_baseu_unofficial_net-3.2 -lwx_baseu_unofficial-3.2 
In other words, using the same wx debs as you, I have the libs that your linker can't find.

If you have them too, then you need to tell CLion where to find them. I don't use that IDE so I can't tell you how, but there's a lot of information (more than most people need ;) ) here.

Regards,

David
Forthro
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Jun 06, 2023 11:58 am

Re: Linker fails to find libraries

Post by Forthro »

Thanks for the answer.
After running wx-config I get this result:

Code: Select all

-L/usr/local/lib -pthread   -lwx_gtk3u_xrc-3.3 -lwx_gtk3u_stc-3.3 -lwx_gtk3u_richtext-3.3 -lwx_gtk3u_ribbon-3.3 -lwx_gtk3u_propgrid-3.3 -lwx_gtk3u_aui-3.3 -lwx_gtk3u_gl-3.3 -lwx_gtk3u_html-3.3 -lwx_gtk3u_qa-3.3 -lwx_gtk3u_core-3.3 -lwx_baseu_xml-3.3 -lwx_baseu_net-3.3 -lwx_baseu-3.3
I'm not sure why their versions are 3.3 and there is no "unofficial" part in their names. What may be relevant is that after getting these linker errors, I've tried this method: https://docs.wxwidgets.org/3.2/plat_gtk_install.html. However, the repo I used was for 3.2 version too and after getting no result I "sudo make uninstalled" it.
wx-config --version, by the way, returns "3.3.0" too.
Last edited by Forthro on Tue Jun 06, 2023 5:13 pm, edited 1 time in total.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Linker fails to find libraries

Post by DavidHart »

So you have wx3.3 installed too, but in /usr/local instead of /usr. That's the default location for a self-build.

What happens if you do:
sudo update-alternatives --display wx-config
That should show if you have multiple wx installs (though I can't remember if it looks in /usr/local too: I never install self-builds there anyway).

You can also use
sudo update-alternatives --config wx-config
to choose a different version.
Forthro
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Jun 06, 2023 11:58 am

Re: Linker fails to find libraries

Post by Forthro »

"sudo update-alternatives --display wx-config" shows me only 3.2 version:

Code: Select all

wx-config - auto mode
  link best version is /usr/lib/x86_64-linux-gnu/wx/config/gtk3-unicode-3.2-unofficial
  link currently points to /usr/lib/x86_64-linux-gnu/wx/config/gtk3-unicode-3.2-unofficial
  link wx-config is /usr/bin/wx-config
/usr/lib/x86_64-linux-gnu/wx/config/base-unicode-3.2-unofficial - priority 327
/usr/lib/x86_64-linux-gnu/wx/config/gtk3-unicode-3.2-unofficial - priority 328
and "sudo update-alternatives --config wx-config" too:

Code: Select all

  Selection    Path                                                             Priority   Status
------------------------------------------------------------
* 0            /usr/lib/x86_64-linux-gnu/wx/config/gtk3-unicode-3.2-unofficial   328       auto mode
  1            /usr/lib/x86_64-linux-gnu/wx/config/base-unicode-3.2-unofficial   327       manual mode
  2            /usr/lib/x86_64-linux-gnu/wx/config/gtk3-unicode-3.2-unofficial   328       manual mode
Last edited by Forthro on Tue Jun 06, 2023 6:01 pm, edited 2 times in total.
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Linker fails to find libraries

Post by DavidHart »

OK. Assuming you don't want to delete the /usr/local/ wx, it looks as if you need, in CLion's linker settings, to set one of the env. variables in the above link to /usr/lib/. Perhaps try LIBRARY_PATH.
Forthro
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Jun 06, 2023 11:58 am

Re: Linker fails to find libraries

Post by Forthro »

Thank you for your help. I've managed to find my mistake and it's very embarrassing. Setting LIBRARY_PATH didn't work. However, I've been statically linking C++ libraries and totally forgot that I had a "-static" linker flag. After removing it, everything started working just fine. I'm so sorry for spending your time on such a stupid mistake and, again, I'm very grateful for your help.
Post Reply