Author Topic: Error while loading shared library  (Read 3340 times)

Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Error while loading shared library
« on: November 30, 2022, 05:12:38 pm »
I try to use OpenCV 4.6.0 with CodeBlocks 20.03 under linuxMint 20. It looks like it compiles ok, but when it comes to running, I receive the message
: error while loading shared libraries: libopencv_core.so.406: cannot open shared object file: No such file or directory
The file in question, as well as all the other .so files, is listed in Global compiler settings ->Linker settings->Link libraries
and the directory it is in is written in the Global compiler settings ->Search directories->Linker

Could anybody tell me what I am missing?
Thank you.


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Error while loading shared library
« Reply #1 on: November 30, 2022, 10:22:19 pm »
1. Using the Global settings instead of project settings tend to cause future issues. It might also cause your current issue.
2. If running outside of Code::Blocks.
2a. copy shared library to the correct location.
2b. Or tell your system where to find the shared library.

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 stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Error while loading shared library
« Reply #2 on: November 30, 2022, 11:20:21 pm »
Link to how to report problem. If you post a build log an Linux person might see the cause of the problem.

https://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

I am a Windows person who has used Linux in the past.

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 mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #3 on: December 01, 2022, 12:34:38 am »
Link to how to report problem. If you post a build log an Linux person might see the cause of the problem.

https://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

I am a Windows person who has used Linux in the past.

Tim S.
I beg your pardon, the link you gave deals with compiler problems, whereas my problem is related to linkage and appears at the run time. As I had stated, the object file is produced ok.

Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #4 on: December 01, 2022, 12:36:10 am »
1. Using the Global settings instead of project settings tend to cause future issues. It might also cause your current issue.
2. If running outside of Code::Blocks.
2a. copy shared library to the correct location.
2b. Or tell your system where to find the shared library.

Tim S.
Once again, as I had formulated in the initial post, all this had been done.

Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #5 on: December 01, 2022, 12:40:53 am »
Even worse, I created two model dummy libraries, static and shared, and I experience the same problem with both of them. The test project does not see any of them.
« Last Edit: December 01, 2022, 01:13:49 am by mihasic »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Error while loading shared library
« Reply #6 on: December 01, 2022, 08:58:26 am »
See the man page for ldconfig and assure your .so files are in the cache.

Offline gd_on

  • Lives here!
  • ****
  • Posts: 796
Re: Error while loading shared library
« Reply #7 on: December 01, 2022, 10:08:02 am »
did you add in your LD_LIBRARY_PATH the path of your .so lib ? This is used by linux at execution time.
If you set the path in code::blocks, it is correctly found at compile and link time. It's why here it's OK.
But when you execute your soft (standalone and even within C::B), linux has not this config in mind.
More, when you build as static, I suppose that you have used a .a file, but it's not always a static lib.
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.4 (tests with 3.3), Msys2 Compilers 13.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #8 on: December 01, 2022, 05:44:28 pm »
did you add in your LD_LIBRARY_PATH the path of your .so lib ? This is used by linux at execution time.
If you set the path in code::blocks, it is correctly found at compile and link time. It's why here it's OK.
But when you execute your soft (standalone and even within C::B), linux has not this config in mind.
More, when you build as static, I suppose that you have used a .a file, but it's not always a static lib.

What is LD_LIBRARY_PATH and where should I add it? I see no such option in CodeBlocks. As I have stated, I added all the .so files with their actual full paths to Settings->Compiler->Linker settings->Link libraries. Besides, I added the directory they are placed in, to Settings->Compiler->Search directories->linker.

Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #9 on: December 01, 2022, 05:49:51 pm »
See the man page for ldconfig and assure your .so files are in the cache.
I beg your pardon, I don't understand a word here. I am a 'windows refugee' and rather new to linux.

Offline gd_on

  • Lives here!
  • ****
  • Posts: 796
Re: Error while loading shared library
« Reply #10 on: December 01, 2022, 07:02:39 pm »
I used Linux in the past ...
Search in google LD_LIBRARY_PATH
For example : https://stackoverflow.com/questions/68298985/how-to-set-ld-library-path-permanently
Apparently, setting/modifying this variable globally (in .bashrc or .profile) is not always a good thing.
There are other ways with ldconfig. Linux specialists will certainly have a better advice...
« Last Edit: December 01, 2022, 07:04:10 pm by gd_on »
Windows 11 64 bits (23H2), svn C::B (last version or almost!), wxWidgets 3.2.4 (tests with 3.3), Msys2 Compilers 13.2.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

Offline jordi

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: Error while loading shared library
« Reply #11 on: December 01, 2022, 07:31:50 pm »
As linuxMint is based on Debian, I assume the paths and files are the same in your system
Code
jordi@debian:/etc$ ll ld.so.conf
-rw-r--r-- 1 root root 34 Jul 29  2019 ld.so.conf
jordi@debian:/etc$ cat ld.so.conf
include /etc/ld.so.conf.d/*.conf

jordi@debian:/etc$ cd ld.so.conf.d/
jordi@debian:/etc/ld.so.conf.d$ ll
total 16
-rw-r--r-- 1 root root  38 Nov 10  2020 fakeroot-x86_64-linux-gnu.conf
-rw-r--r-- 1 root root  44 Jul 29  2019 libc.conf
-rw-r--r-- 1 root root 100 May  1  2021 x86_64-linux-gnu.conf
-rw-r--r-- 1 root root  56 Oct  2  2021 zz_i386-biarch-compat.conf
jordi@debian:/etc/ld.so.conf.d$ cat libc.conf
# libc default configuration
/usr/local/lib
Create a .conf file for opencv and add the path where the libraries are (as the content in libc.conf file)

Command to update changes done in configuration files (you will need super-user privileges).
sudo /usr/sbin/ldconfig -v
Maybe it doesn't work for you. Search how to execute commands as superuser in linuxMint

Example: command to see all the dynamic libraries whick contains the "open" word
Code
jordi@debian:/etc/ld.so.conf.d$ /usr/sbin/ldconfig -p | grep -i open
libopensc.so.7 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopensc.so.7
libopenmpt.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopenmpt.so.0
libopenjp2.so.7 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopenjp2.so.7
libopencore-amrwb.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopencore-amrwb.so.0
libopencore-amrnb.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopencore-amrnb.so.0
libopenal.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libopenal.so.1
libOpenNI2.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libOpenNI2.so.0
libOpenGL.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libOpenGL.so.0
libOpenGL.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libOpenGL.so
libOpenCL.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libOpenCL.so.1


Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #12 on: December 01, 2022, 08:11:58 pm »
I beg your pardon once again, I thought it was a CodeBlocks forum. I chose CodeBlocks in order to simplify the creation of my applications. I know very well that C++ code can be compiled and linked without using an IDE, directly with system commands. If it is simpler than with CodeBlocks, then what is the reason for CodeBlocks to exist?

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Error while loading shared library
« Reply #13 on: December 01, 2022, 09:20:22 pm »
As you said yourself, your application does compile fine, so you don't have a compile time problem. You have a runtime problem. Changing the compiler configuration will do nothing, because your application is not RUN by the compiler but by your OS, Linux in your case.

Actually, your problem is not a CodeBlocks problem but a Linux problem, so technically offtopic here. If you stop beeing so ignorant you still might get some help here.

There are multiple ways to configure the Linux dynamic library loader. If you install libraries with the package manager this should not be necessary and should just work, so the first question is, how did you actually get OpenCV on your system? Second question is, is it really OpenCV that is missing or might this library itself miss something else? To answer that question, run
Code
ldd <your-application-binary-goes-here>
and post the output.

Offline mihasic

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Error while loading shared library
« Reply #14 on: December 01, 2022, 11:00:46 pm »
As you said yourself, your application does compile fine, so you don't have a compile time problem. You have a runtime problem. Changing the compiler configuration will do nothing, because your application is not RUN by the compiler but by your OS, Linux in your case.

Actually, your problem is not a CodeBlocks problem but a Linux problem, so technically offtopic here. If you stop beeing so ignorant you still might get some help here.

There are multiple ways to configure the Linux dynamic library loader. If you install libraries with the package manager this should not be necessary and should just work, so the first question is, how did you actually get OpenCV on your system? Second question is, is it really OpenCV that is missing or might this library itself miss something else? To answer that question, run
Code
ldd <your-application-binary-goes-here>
and post the output.
Frankly speaking, I don't like you being so aggressive, but nevertheless, I will answer.
- I believed that CodeBlocks was an IDE, not just a compiler. IDE, as I understand it, not only compiles, but also guides the whole build process, including linking. As far as I see, my problem is that the linker does not find the libraries, although I filled-in in the CodeBlocks interface all the fields I could find that seemed related to linker configuration. If, as you say, the 'Linux dynamic library loader' is not configured after that, I believe it an IDE bug. Or I may be missing something in the IDE interface - that was my question.
- As for the installation, in Mint there is a list of applications that can be installed by the system automatically, I made confidence to this option.
- As for your hypothesis that it could be something wrong in the library itself, I don't think it could be the case. First, the message at run time clearly says that the required file could not be found. I think that kind of message is produced before accessing the file in question.  Second, as I have already reported, I tried to explore the problem with model dummy libraries, produced with this very CodeBlocks installation, and it gave exactly the same result.

Anyhow, I see the problem is really complicated, I apologize for bothering the forum with it. Thanks to all who tried to help me and good luck.