-wl,rpath= options in GCC

Source: Internet
Author: User

When GCC compiles a link to a dynamic library, it is very likely that it will compile, but when it does, it cannot find the dynamic link library, which is

Because the path specified by the-l option is only valid at compile time, the compiled executable does not know the value after the-l option,

Of course I can't find them. You can use LDD <your_execute> to see if there is no ' not found ' behind the library you are linking to,

The workaround is to use-WL,RPATH=<YOUR_LIB_DIR>, which enables execute to remember the location of the link library

Gcc-o Foo foo.c-l/usr/local/lib-lfoo-wl,-rpath=/usr/local/lib
Gcc-o foo foo.c-l$ (prefix)/lib-lfoo-wl,-rpath=$ (prefix)/lib
re:linking With-wl,-rpath and $ (prefix)From: "Nelson H. F. Beebe" <beebe at the math dot Utah dot edu> to:gcc-help at gcc dot gnu dot org cc:beebe at math do T Utah dot edu, "David carter-hitchin" <david at carter-hitchin dot clara Dot co dot uk> Date:fri, 2 Dec 2005 17:18 : 18-0700 (MST) Subject:Re:linking With-wl,-rpath and $ (prefix)
"David Carter-hitchin" <david@carter-hitchin.clara.co.uk> asks on Fri, 2 Dec 2005 23:47:28-0000 About-wl,-rpath ve

Rsus-l. THE-L option supplies a colon-separated the library path that was to was searched at the LINK time for libraries. Thus cc-o foo Foo.c-l/usr/local/lib-lfoo means that either LIBFOO.A or libfoo.so should is found in Either/usr/loca L/lib, or elsewhere in the default search patch (in Gnu/linux, the directories can is listed in/etc/ld.so.conf, and the C

Ache updated by Running/etc/ldconfig). Whether the. A or. So form of the library is needed are platform dependent (e.g., IBM AIX uses only the. a form), and also  dependent on compiler options to select dynamic or static linking.

The default is normally dynamic linking to save disk space and waste CPU time.  However, this means and the executable Foo may have been successfully linked against a GKFX library, at RUN time, The Run-time loader looks for it in the default search path, possibly prefixed by a Colon-separated List of libraries supplied by the Ld_library_path variable. If, in our example,/usr/local/lib are not part of the of the default path and then the Run-time loader would not being able to find the

Shared library, even THOUGH linking succeeded (because of the-l/usr/local/lib option).  You can check whether shared libraries can is found by running Env-i ldd foo (the "env-i" says-ignore any existing

Environment variables, such as Ld_library_path). For example, on one of my systems, I find% env-i ldd/usr/local/bin/emacs libxaw3d.so.5 = = (File not Foun

d) libxmu.so.4 =/usr/lib/libxmu.so.4 libxt.so.4 =/usr/lib/libxt.so.4 ...  Notice the "(File not Found") line. That library was actually present on that system In/usr/local/lib, and I can make it succeed like this:% env-i LD_LIBR
        	Ary_path=/usr/local/lib Ldd/usr/local/bin/emacs libxaw3d.so.5 =/usr/local/lib/libxaw3d.so.5 Libxmu.so.4 =/usr/lib/libxmu.so.4
		...  Thus, when shared libraries is present in nondefault directories, you need to supply an additional linker option, usually  -R or-wl,-rpath=, with a run-time library path. Our example above becomes-gcc gcc-o foo foo.c-l/usr/local/lib-lfoo-wl,-rpath=/usr/local/lib in a Makefile, I wo  Uld write this as gcc-o foo foo.c-l$ (prefix)/lib-lfoo-wl,-rpath=$ (prefix)/lib so, the same library path is used  At link time as at run time, and so, the executable file, foo, records the path. With the GNU autoconf, the normal condition are that prefix are the root of the file tree into which you install software Locall  Y, so the above command is fairly typical. Unfortunately, software developers who has nondefault library search paths often forget to supply The-wl,-rpath or-r op

tions in their makefiles, with the result of the code builds and runs at their sites, but not at end user sites. >from notes that I Keep: >> ... >> Unfortunately, there is at LEAsT three incompatible kinds of >> command-line options that's the compiler to instruct the linker to >> save Library paths in the executable: >> >>-wl,-rpath,/path/to/dir gcc, g++, FreeBSD, SGI, Sun compilers &GT;&G 	T -rpath/path/to/dir Compaq/dec, SGI compilers >>-rdir:dir:dir Portland Group, Sun compilers >> >> N
Otice. SGI and Sun support, such flavors.

>> ... In my view, there are clearly brain damage here: (1) compiler writers should has standardized on the same option name for Recording the Run-time library path (I ' d vote for-r), and (2) the linker should really record the Run-time library path b

Y default, so that-r would almost never is needed. --------------------------------------------------------------------------------Nelson H. F. Beebe Te L: +1 801 581 5254--University of Utah 传真: +1 801 581 4148--de Partment of Mathematics, 1LCB Internet e-mail:beebe@math.utah.edu--155 S 1400 e RM 233 beebe@acm.org Beebe@compute r.org-Salt Lake City, UT 84112-0090, USA url:http://www.math.utah.edu/~beebe----------------------------------- ---------------------------------------------

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.