Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: merging multiple static library

117 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted

frakie

unread,
Sep 7, 2007, 10:22:04 AM9/7/07
to
Hi 'body,
I'm trying to compile a program which uses two static libraries.
One is wrote in C language the other is wrote in C++ but it's
functions are under extern "C" declaration.
Once I try to compile my file example.c I have to add the option -
lstdc
++ 'cause of the C++ library.
I would like to avoid this option, so i tried to merge the C++
library
with libstdc++.a as follows:
mkdir junk
cd junk
ar x ../libmyC++lib.a
ar x ../stdlibc++.a
rm -f ../libmergedC++Lib.a
ar r ../libmergedC++Lib.a *.o

compiling my example.c
gcc example.c -L. -lmyCLib -lmergedC++Lib


file i get


home/myUser/lib/libmergedC++lib.a(ios-inst.o)
(.text._ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc+0xd5): In
function `std::basic_ios<char, std::char_traits<char> >::widen(char)
const':
: undefined reference to `__stack_chk_fail'
/home/myUser/lib/libmergedC++lib.a(istream-inst.o)
(.text._ZNSi5seekgExSt12_Ios_Seekdir+0xb1): In function
`std::basic_istream<char, std::char_traits<char> >::seekg(long long,
std::_Ios_Seekdir)':
: undefined reference to `__stack_chk_fail'
/home/myUser/lib/libmergedC++lib.a(istream-inst.o)
(.text._ZNSi5seekgESt4fposI11__mbstate_tE+0xd1): In function
`std::basic_istream<char, std::char_traits<char>
>::seekg(std::fpos<__mbstate_t>)':
: undefined reference to `__stack_chk_fail'
/home/myUser/lib/libmergedC++lib.a(istream-inst.o)
(.text._ZNSt13basic_istreamIwSt11char_traitsIwEE5seekgExSt12_Ios_Seekdir
+0xb1): In function `std::basic_istream<wchar_t,
std::char_traits<wchar_t> >::seekg(long long, std::_Ios_Seekdir)':
: undefined reference to `__stack_chk_fail'
/home/myUser/lib/libmergedC++lib.a(istream-inst.o)
(.text._ZNSt13basic_istreamIwSt11char_traitsIwEE5seekgESt4fposI11__mbstate_­
tE
+0xd1): In function `std::basic_istream<wchar_t,
std::char_traits<wchar_t> >::seekg(std::fpos<__mbstate_t>)':
: undefined reference to `__stack_chk_fail'
/home/myUser/lib/libmergedC++lib.a(locale-inst.o)
(.text._ZNKSt8time_getIcSt19istreambuf_iteratorIcSt11char_traitsIcEEE15_M_e­
xtract_nameES3_S3_RiPPKcjRSt8ios_baseRSt12_Ios_Iostate
+0x602): more undefined references to `__stack_chk_fail' follow
/home/myUser/lib/libmergedC++lib.a(cp-demangle.o)(.text
+0x3fb7): In function `d_demangle':
: undefined reference to `__stack_chk_fail_local'
collect2: ld returned 1 exit status
make[2]: *** [example] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

What's going wrong???

Paul Pluzhnikov

unread,
Sep 7, 2007, 10:40:20 PM9/7/07
to
frakie <frak...@gmail.com> writes:

> I'm trying to compile a program which uses two static libraries.
> One is wrote in C language the other is wrote in C++ but it's
> functions are under extern "C" declaration.
> Once I try to compile my file example.c I have to add the option -lstdc++
> 'cause of the C++ library.

Correct way to build C++ programs is to compile and link them with
appropriate compiler driver. Don't do this:

gcc example.c -lstdc++

Do this instead:

gcc -c example.c
g++ example.o

If what you *really* are trying to achive is to get rid of
libstdc++.so dependency, then a recipe can be found here:
http://groups.google.com/group/comp.unix.programmer/msg/16aaa50e2d88cf8

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

frakie

unread,
Sep 10, 2007, 4:05:52 AM9/10/07
to
On 8 Set, 04:40, Paul Pluzhnikov <ppluzhnikov-...@charter.net> wrote:

No, that's not what I'm saying... :(

I need to release a library, which is made using another one.
The one i have to release does have to be standing by itself, and must
be used
without any link to other libraries.
It has to be used to build C programs, without any C++ references.
That's the meaning of my question.

Message has been deleted
0 new messages