Книга: Embedded Linux development using Eclipse
4.7 Linking Projects
4.7 Linking Projects
Eclipse allows projects to refer to, and to depend on, other projects. Consider, for example, that you have a family of similar application projects that all make use of a common library. We can have each of the application projects refer to the library project so that any time a change is made in the library, the applications are rebuilt. The library project becomes a dependency of the applications.
To illustrate this idea, we’ll take the five functions in sort_utils.c
and turn them into a static library that we’ll link with record_sort.c
. Switch back to the C/C++ perspective, select File?New… C Project and select Static Library as the project type. Call it “sort.” Click Finish. Right-click on the sort project in Project Explorer and select Import?General?File System. Browse to EclipseSamples/sort/
. Click Select All and Finish. Five C files and one header file are imported into the project. Build the project. The result is libsort.a
.
Now go back to the record_sort project and select Properties from the Project Explorer context menu. Select Project References and check sort
, which may be the only entry (Figure 4.12). Delete sort_utils.c
from the file list.
Figure 4.12: Project References.
Now expand the C/C++ General entry in the left-hand pane and select Paths and symbols. Click the References tab and check sort. This will expand the sort entry and you’ll see that the Active build configuration is selected. Select the Library paths tab and you’ll see that /sort/Debug has been added (assuming that Debug is the active configuration for sort).
Expand the C/C++ Build entry and select Settings. Then select GCC C Linker?General and check No shared libraries. We’ll be using static libraries in this example. Now select Libraries (Figure 4.13). The Library search path lists the path to the sort project.
Figure 4.13: Library selection.
Click the Add icon in the Libraries section and enter “sort.”[3] In the context menu for record_sort in the Project Explorer, clean the project. This will rebuild it using the sort library. To prove that record_sort is now dependent on sort, clean the sort project.
This causes it to be rebuilt with a later timestamp on the library than that of the record_sort executable. Now build record_sort. It will be relinked with the new library.
- 2.3 Executable and Linking Format
- Managing Software Projects with Subversion
- CHAPTER 6 Simple PIC18 Projects
- CHAPTER 7 Advanced PIC18 Projects — SD Card Projects
- CHAPTER 8 Advanced PIC18 Projects — USB Bus Projects
- CHAPTER 9 Advanced PIC18 Projects — CAN Bus Projects
- 2.2 Overview of Linkers and the Linking Process
- Lesson 2: Configuring Windows Embedded CE Subprojects
- Advanced PIC Microcontroller Projects in C
- Windows Embedded Subprojects Overview
- Types of Subprojects
- Creating and Adding Subprojects to an OS Design