From the rtspplayer demo program running on the mobile phone, we can see the GCC-rpath and-rpath-link options.

Source: Internet
Author: User
When the rtspplayer program runs on a mobile phone, fbsink is used as the video sink component. This is a video sink component using framebuffer. Therefore, in the Code, it is natural that you only need to replace xvimagesink with fbsink in the case of stst_element_factory_make. However, after the program is compiled in scratchbox, it is transferred to the mobile phone, but an error occurs. The report says:

No such element... 'fbsind'

The strange thing is that this element can be found on the mobile phone by using the command "alkaline-GST-inspect | grep" fbsink. Later I learned that the element fbsink exists in the/opt/Alkaline/lib/libalp_media.so file. This. So file is not within the search range of the dynamic link library during the runtime of rtspplayer. Therefore, fbsink fails to be created.

How can I make the libalp_media.so file exist in the search range of the dynamic link library in the rtspplayer runtime? It's easy to add-L/opt/Alkaline/lib-lalp_media during compilation. That is to say, although the Code does not explicitly call the function in this. So, we can manually use this. So as a dependency link during compilation, so that it is OK. However, a compilation error occurs after such content is added:

Gcc-wall-g-o rtspplayer 'pkg-config -- cflags -- libs GTK +-2.0 '-I/usr/include/gstreamer-0.10-L/opt/Alkaline/lib-lststfusion- lalp_media main. c. gstplay-marshal.c C
/Scratchbox/compilers/ARM-Linux-gnueabi/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.1.2/export warning: libalp_audiomgr.so, needed by/opt/Alkaline/lib/libalp_media.so, not found (try using-rpath or-rpath-link)
/Scratchbox/compilers/ARM-Linux-gnueabi/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.1.2/export warning: libalp_staudiomgrsrc.so, needed by/opt/Alkaline/lib/libalp_media.so, not found (try using-rpath or-rpath-link)
/Scratchbox/compilers/ARM-Linux-gnueabi/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.1.2/export warning: libalp_staudiomgrsink.so, needed by/opt/Alkaline/lib/libalp_media.so, not found (try using-rpath or-rpath-link)
/Scratchbox/compilers/ARM-Linux-gnueabi/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.1.2/export warning: libalp_core.so, needed by/opt/Alkaline/lib/libalp_media.so, not found (try using-rpath or-rpath-link)
/Scratchbox/compilers/ARM-Linux-gnueabi/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.1.2/export warning: libalp_sysutils.so, needed by/opt/Alkaline/lib/libalp_media.so, not found (try using-rpath or-rpath-link)
/Scratchbox/compilers/ARM-Linux-gnueabi/bin /.. /lib/GCC/ARM-None-Linux-gnueabi/4.1.2/export warning: libalp_drm1.so, needed by/opt/Alkaline/lib/libalp_media.so, not found (try using-rpath or-rpath-link)
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_fclose'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_message_get_message_id'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ settings_open'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_message_unpack_start'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ Log'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ settings_close'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_is_drm_file'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ settings_init'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_fseek'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_fopen_with_permission'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ settings_get'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_connection_register_disconnect_callback'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_message_unpack_end'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_channel_connect'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_connection_register_receive_callback'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_check_rights_info'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_message_unpack_int32'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_ftell'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ settings_value_clean'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ ipc_message_unpack_string'
/Opt/Alkaline/lib/libalp_media.so: Undefined reference to 'alkaline _ drm_fread'
Collect2: LD returned 1 exit status
Make: *** [rtspplayer] Error 1

This error report says that a bunch of so files, such as libalp_staudiomgrsrc.so, cannot be found. These so files are all located in the/opt/Alkaline/lib directory, which is required by libalp_media.so. In other words, the required dynamic link library still exists in libalp_media.so.

In this case, the-rpath and-rpath-link options emerge. In fact, we spent so much effort to add libalp_media.so to the dynamic link library search list of rtspplayer. Specifically, we use the command LDD. /rtspplayer, you can see the line libalp_media.so.

-Rpath/-rpath-link are actually LD options, not GCC. GCC is just a wrapper that combines Preprocessor, assemble, and link. -Rpath <dir> is used to manually specify a directory as one. so file search directory, which has priority in LD_LIBRARY_PATH and/etc/lD. so. conf... defined in these places. so file search directory. This directory is specified by program developers during compilation, so it cannot be modified when the program runs on another machine in the future.

-Rpath-link is similar to-rpath, but-rpath-link <dir> specifies a dynamic link library required by the program, if you need other dynamic link libraries (as we do here, libalp_media.so also needs other libraries. so), to which/which directory to find the desired directory. so. In addition, unlike-rpath, the directory defined in-rpath-link may not be seen in the output of LDD <exec>, because the directory defined here is not required by the program itself.

After understanding the meaning of these two options, we can see the usage. to directly use these two options in the GCC command line, you must follow the Syntax:-wl ,....... For example,-wl, -- rpath-link/opt/Alkaline/lib. -Wl tells GCC that the subsequent content is the option passed to linker. -WL is not required if you use LD directly. Therefore, the above compilation command becomes like this, and it is OK:

Gcc-wall-g-o rtspplayer-wl, -- rpath-link/opt/Alkaline/lib 'pkg-config -- cflags -- libs GTK +-2.0 '-I/usr/include/gstreamer-0.10-L/opt/Alkaline/lib- lststfusion-lalp_media main. c. gstplay-marshal.c C

In this way, the generated rtspplayer can be copied to the mobile phone again, And fbsink element cannot be found again.

Here is a list of specific keywords that pass option to the consumer er, Preprocessor, and linker in the GCC command line:

Code: select all
  -Wa,<options>            Pass comma-separated <options> on to the assembler
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor
  -Wl,<options>            Pass comma-separated <options> on to the linker

You can also define LD_LIBRARY_PATH. In this way, you do not need to add-wl, -- rpath-link/opt/Alkaline/lib. For details about how to find the logic of the dynamic link library, refer to the man lD's explanation of-rpath and-rpath-link.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.