Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the reason for executing the file prompt No such file or directory in linux

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what is the reason for the implementation of the file prompt No such file or directory in linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what is the reason for the implementation of the file prompt No such file or directory in linux" this article.

1 background

Recently, I have been studying to get a compiler system in the linux system of the ZC706-ARM development board (which does not support apt). I happened to find that the company has a set of Nvidia ARM development board and has a ubunut system (which supports apt). Can the program compiled on the Nvidia board run on the ZC706 board?

2 process

Gcc a.c generates a.out in Nvidia's development board, and then copies it to ZC706 to execute the occurrence of "No such file or directory"

I have encountered the following reasons in the past:

The file itself does not exist or is corrupted

No execute permission (chmod 777 xxx)

The number of bits in the system is different from that in the program

However, after the following process, it is found that ZC706 is missing the specified loader for the xx program:

1. Troubleshoot problems such as file corruption-> regenerate copy verification

two。 Troubleshoot program permissions-- > chmod 777 xx & & ls-all

3. Troubleshoot architectural issues through unanme-a

4. Compare the differences between normally executed files and error execution files through commands such as readelf file

Verification process:

| a.out is compiled and generated by Nvidia GCC and zc706 has the above problems | b.out is generated by cross-compilation of x86 ubunut and can be executed normally |

Later, it was found that the loader could also cause this phenomenon through google and so on. From the following, it can be found that the main difference between the two is interpreter.

Solution:

1. Unify the relationship between compiler and library

two。 Establish a soft link ln-s / lib/ld-linux.so.3 / lib/ld-linux-armhf.so.3

3. When compiling the program, add the-static option to statically link the program, that is, do not use dynamic libraries

Root@tegra-ubuntu:~# readelf-h a.outELF Header: Magic: 7f 45 4c 46 01 01 00 00 00 Class: ELF32 Data: 2's complement Little endian Version: 1 (current) OS/ABI: UNIX-System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0x8315 Start of program headers: 52 (bytes into file) Start of section headers: 4500 (bytes into file) Flags: 0x5000402, has entry point, Version5 EABI Hard-float ABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 9 Size of section headers: 40 (bytes) Number of section headers: 30 Section header string table index: 27root@tegra-ubuntu:~# readelf-h b.outELF Header: Magic: 7f 45 4c 46 01 01 00 00 00 Class: ELF32 Data: 2 seconds complement Little endian Version: 1 (current) OS/ABI: UNIX-System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0x86bc Start of program headers: 52 (bytes into file) Start of section headers: 4136 (bytes into file) Flags: 0x5000202, has entry point, Version5 EABI Soft-float ABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 8 Size of section headers: 40 (bytes) Number of section headers: 31 Section header string table index: 28root@tegra-ubuntu:~# readelf-l helloworld | grep interpreterreadelf: Error: 'helloworld': No such fileroot@tegra-ubuntu:~# readelf-l a.out | grep interpreter [Requesting program interpreter: / lib/ld-linux-armhf .so.3] root@tegra-ubuntu:~# readelf-l b.out | grep interpreter [Requesting program interpreter: / lib/ld-linux.so.3]

3 introduce ld loader

Linux uses this ld-linux.so* (the ubuntu of virtual machine x86 uses ld-linux.so2) to load (it's really just a link) other libraries. So the library must be placed in linux / lib. For others, our shared libraries are usually placed under the / lib path, which is the default search path for the system.

Search paths for Linux shared libraries in sequence:

1. The dynamic library search path specified when compiling the object code: specify the-Wl,-rpath= path when compiling

2. The dynamic library search path specified by the environment variable LD_LIBRARY_PATH

3. Dynamic library search path specified in configuration file / etc/ld.so.conf

4. Default dynamic library search path / lib

5. Default dynamic library search path / usr/lib

Note:

1. Some development boards will find that / etc does not have ld.so.conf, and running ldconfig will prompt "ldconfig: Warning: ignoring configuration file that cannot be opened: / etc/ld.so.conf: No such file or directory"

Solution: add the library to the environment variable, and then ldconfig-v (/ sbin/ldconfig: relative path `- v' used to build cache)

two。 Shared library cnnot open shared object

Test whether to connect dynamically. If libtest.so is listed, then the connection should be normal.

At this time, the libtest.so can not be found, because there is a problem with the search path of the dynamic link library, so you can join the dynamic library above to find the location.

3 the ldconfig command mainly searches the shareable dynamic link libraries (format above, lib*.so*) under the default search directory (/ lib and / usr/lib) and the directory listed in the dynamic library configuration file / etc/ld.so.conf, and then creates the connection and cache files required by the dynamic loader (ld.so).

4 LD_LIBRARY_PATH: this environment variable indicates the path where the dynamic connector can load the dynamic library. If you have root permission, you can modify the / etc/ld.so.conf file, and then call / sbin/ldconfig to achieve the same purpose, but if you do not have root permission, you can only use the method of outputting LD_LIBRARY_PATH, using the bash command)

The above is all the content of the article "what is the reason for the implementation of the file prompt No such file or directory in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report