[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Static Library Linking Problem using Autotool
From: |
Wy kevinthesun |
Subject: |
Static Library Linking Problem using Autotool |
Date: |
Mon, 27 Oct 2014 20:34:22 -0700 |
Hi,
I am using GNU Autotool toolchain to work in Eclipse. I have some problems
with linking to static library.
First, I create a static library project "GPIOPin" and successfully
compiling it with following Makefile.am:
noinst_LIBRARIES = libGPIOPin.a
libGPIOPin_a_SOURCES = GPIOPin.cpp GPIOPin.h
AM_CXXFLAGS = @GPIOPin_CFLAGS@
AM_LDFLAGS = @GPIOPin_LIBS@
CLEANFILES = *~
Then I created a test project "Test3" which included "GPIOPin.h". I wrote
the following Makefile.am for Test3:
bin_PROGRAMS = Test3
Test3_SOURCES = Test3.cpp
Test3_LDFLAGS = -L/home/kevinthefire/workspace/GPIOPin/src
Test3_LDADD = /home/kevinthefire/workspace/GPIOPin/src/libGPIOPin.a
AM_CXXFLAGS = -I/home/kevinthefire/workspace/GPIOPin/src
AM_LDFLAGS = @Test3_LIBS@ @Test3_LDFLAGS@
AM_LDADD = @Test3_LDADD@
CLEANFILES = *~
It was compiled and running well.
Then I tried to create another static library "Encoder" which needed to
include GPIOPin library. I wrote the following Makefile.am:
noinst_LIBRARIES = libEncoder.a
libEncoder_a_SOURCES = Encoder.cpp Encoder.h
Encoder_LDFLAGS = -L/home/kevinthefire/workspace/GPIOPin/src
Encoder_LDADD = /home/kevinthefire/workspace/GPIOPin/src/libGPIOPin.a
AM_CXXFLAGS = -I/home/kevinthefire/workspace/GPIOPin/src
AM_LDFLAGS = @Encoder_LIBS@ @Encoder_LDFLAGS@
AM_LDADD = @Encoder_LDADD@
CLEANFILES = *~
It could be compiled well.
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:
Description Resource Path Location Type
make[1]: *** [all-recursive] Error 1 Test6 C/C++ Problem
make[2]: *** [Test6] Error 1 Test6 C/C++ Problem
undefined reference to `GpIoPin::setEdge(char*)' Encoder.cpp
/Encoder/src line 87 C/C++ Problem
undefined reference to `GpIoPin::setEdge(char*)' Encoder.cpp
/Encoder/src line 88 C/C++ Problem
make: *** [all] Error 2 Test6 C/C++ Problem
more undefined references to `GpIoPin::~GpIoPin()' follow Test6
line 25 C/C++ Problem
undefined reference to `GpIoPin::~GpIoPin()' Encoder.h
/Encoder/src line 25 C/C++ Problem
undefined reference to `GpIoPin::~GpIoPin()' Encoder.h
/Encoder/src line 26 C/C++ Problem
undefined reference to `GpIoPin::GpIoPin(unsigned int, bool)'
Encoder.h /Encoder/src line 25 C/C++ Problem
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.
Thank you for any help!
Kevin
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Static Library Linking Problem using Autotool,
Wy kevinthesun <=