Scons User Guide Chapter 4: compiling and linking library files

Source: Internet
Author: User
Tags python list

1. Compile the library file

You can use the library method to compile the library file: Library ('foo', ['f1. c', 'f2. c', 'f3. C ']) scons will use the appropriate library prefix and suffix based on your system. Therefore, in the POSIX system, the above example will be compiled as follows: % scons-QCC-O f1.o-C f1.ccc-O f2.o-C f2.ccc-O f3.o-C f3.car RC libfoo. A f1.o f2.o f3.oranlib libfoo. a. If you do not display the name of the specified target database, scons uses the name of the first source file.
1.1 Use source code or target file to compile the library fileIn addition to the source file, the Library can also use the target file, as shown below: Library ('foo', ['f1. c', 'f2. o', 'f3. c', 'f4. o'])
1.2 use staticlibrary to display and compile static databasesLibrary functions are used to compile static libraries. If you want to display the specified static library to be compiled, you can use staticlibrary instead of Library: staticlibrary ('foo', ['f1. c', 'f2. c', 'f3. c'])
1.3 Use sharedlibrary to compile a dynamic libraryTo compile a dynamic library (in the POSIX system) or DLL file (in Windows), you can use sharedlibrary: sharedlibrary ('foo', ['f1. c', 'f2. c', 'f3. C ']) Run scons compilation in POSIX: % scons-QCC-O f1. OS-C f1.ccc-O f2. OS-C f2.ccc-O f3. OS-C f3.ccc-O libfoo. so-shared f1. OS f2. OS f3. OS
2. link library filesWhen linking a library file, use the $ libs variable to specify the library file and use $ libpath to specify the directory for storing the library file: Library ('foo', ['f1. c', 'f2. c', 'f3. C ']) Program ('prog. c', Libs = ['foo', 'bar'], libpath = '. ') You do not need to specify the library file prefix (such as Lib) or suffix (such. A or. lib), scons will automatically match. % Scons-QCC-O f1. OS-C f1.ccc-O f2. OS-C f2.ccc-O f3. OS-C f3.car RC libfoo. A f1.o f2.o f3.oranlib libfoo. ACC-O Prog. o-C Prog. CCC-O prog Prog. o-l. -lfoo-lbar
3. $ libpath tells you where to find the libraryBy default, the linker only searches for library files in the default library directory of the system. Scons also searches for library files in the directory specified by $ libpath. $ Libpath consists of a directory list, as shown below: Program ('prog. C ', Libs = 'M', libpath = ['/usr/lib ','/usr/local/lib ']) the advantage of using the python list is that it can be used across platforms. Another optional method is to connect the library directory with the system-specific path separator into a string: In the POSIX system: libpath = '/usr/lib: /usr/local/lib 'in Windows: libpath = 'C: \ Lib; D: \ Lib' when the linker is executed, scons will create a suitable flags, allows the linker to search for library files in the specified library directory. The above example is compiled in the POSIX system: % scons-QCC-O Prog. o-C Prog. CCC-O prog Prog. o-L/usr/lib-L/usr/local/lib-LM

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.