Go to: operation parameters and explanations for using dynamic and static library links in GCC

Source: Internet
Author: User

From: http://blog.sina.com.cn/s/blog_4cb133e5010009zx.html

 

In a system we developed, there is no problem during compilation because one of the dynamic libraries is dynamically linked, but it cannot be executed during runtime. If the library is statically connected, run without any problems. The specific reasons have not been clarified, and the right should be taken as a temporary solution.

How to use dynamic and static library links at the same time, colleague Zhou Nan provides a parameter usage. The specific parameters in the GCC command parameters are as follows:-wl, -bstatic-L/usr/local/SQLite-arm-Linux /. description of libs-lsqlite-wl,-bdynamic-L/usr/local/ARM/3.3.2/lib: static connection of SQLite library and dynamic connection of other libraries. -Wl,-bstatic and-wl,-bdynamic parameters can be understood literally, with static and dynamic meanings, however, the actual rules are described in the original GCC manual. Original article:

Note-if the linker is being invoked indirectly, via a compiler Driver (eggcc) Then all the linker command line options shoshould be prefixed-Wl,(Or whatever is appropriate for the participating compiler driver) like this:

 gcc -Wl,--startgroup foo.o bar.o -Wl,--endgroup
 

This is important, because otherwise the compiler driver program may silently drop the linker options, resulting in a bad link.

 

In fact, it mainly applies linker parameters implicitly and uses "-wl," to identify, "-- startgroup Foo. O Bar. o-wl, -- endgroup "indicates a group, and-bstatic-bdynamic is used as the keyword and-wl, which cannot be divided. When GCC connects to the database, the default link is a dynamic link, currently, the preceding command limits the use of static links when linking to the SQLite library.

 

-Bstatic has three other statements:-DN and-Non_shared and-static

-Bdynamic has two other methods:-dyAnd-call_shared

The preceding parameter "-l/usr/local/SQLite-arm-Linux /. libs is not placed in-wl ,... it doesn't matter, because it only provides the location of the SQLite dynamic and static library. You can change it to the following parameter format to make it more intuitive.

 

-L/usr/local/SQLite-arm-Linux/. libs-L/usr/local/ARM/3.3.2/lib-wl,-DN-lsqlite-wl,-dy

 

-Wl,-DN and-wl,-dy appear in pairs to play the role of the title.

 

For-wl, there are still many parameters that follow, and I cannot understand them all.

 

There is another issue worth noting. There cannot be spaces behind-Wl; otherwise, an error will occur!

 

About-Wl, Option Note:

 

GCC Command Parameters

 

-Wl, Option

Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.

The option parameter is passed as a linker parameter. If option contains a comma, several parameters are cut into commas.

 

For example:

-Wl,-DN-lsqlite

-Static link starting with DN

-Lsqlite static link SQLite Library

After the static link is complete, the dynamic link is required.

-Wl,-dy

Restart the dynamic 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.