[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Static Library Linking Problem using Autotool
From: |
Gavin Smith |
Subject: |
Re: Static Library Linking Problem using Autotool |
Date: |
Fri, 14 Nov 2014 18:10:39 +0000 |
On Tue, Oct 28, 2014 at 3:34 AM, Wy kevinthesun <address@hidden> wrote:
> Finally I tried to test Encoder library as before. I create "Test6" Project
> which only included "Encoder.h" and wrote Makefile.am similarly as Test3:
>
> bin_PROGRAMS = Test6
> Test6_SOURCES = Test6.cpp
>
> Test6_LDFLAGS = -L/home/kevinthefire/workspace/Encoder/src
> Test6_LDADD = /home/kevinthefire/workspace/Encoder/src/libEncoder.a
>
> AM_CXXFLAGS = -I/home/kevinthefire/workspace/Encoder/src
> AM_LDFLAGS = @Test6_LIBS@ @Test6_LDFLAGS@
> AM_LDADD = @Test6_LDADD@
> CLEANFILES = *~
>
> It gave errors:
[...]
)
> It seems that the compiler couldn't link to GPIOPIn library through Encoder
> library? So I modified Makefile.am of Test6 as:
>
> bin_PROGRAMS = Test6
> Test6_SOURCES = Test6.cpp
>
> Test6_LDFLAGS = -L/home/kevinthefire/workspace/Encoder/src
> -L/home/kevinthefire/workspace/GPIOPin/src
> Test6_LDADD = /home/kevinthefire/workspace/Encoder/src/libEncoder.a
> /home/kevinthefire/workspace/GPIOPin/src/libGPIOPin.a
>
> AM_CXXFLAGS = -I/home/kevinthefire/workspace/Encoder/src
> -I/home/kevinthefire/workspace/GPIOPin/src
> AM_LDFLAGS = @Test6_LIBS@ @Test6_LDFLAGS@
> AM_LDADD = @Test6_LDADD@
> CLEANFILES = *~
>
> I just added information of GPIOPin library and it compiled well!
>
> Now I am wondering why I can't write Makefile.am of Test6 as simple as
> Test3, but have to list all the library information(GPIOPin and Encoder).
> If my Encoder library includes several libraries I created, writing
> Makefile.am would be trouble.
>
As you have found, the linker needs to be told about all libraries
that are going to contribute to the produced executable. If you find
it time-consuming to keep track of what other libraries a library
requires, you might consider using a program called "pkg-config"
(http://www.freedesktop.org/wiki/Software/pkg-config/), which can
retrieve these dependencies so they can be included in the link
command.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Static Library Linking Problem using Autotool,
Gavin Smith <=