1

I want to make a static library called libXYZ.a using some existing static libraries: libX.a, libY.a, libZ.a and some object files. The command line I used to build the static library libXYZ.a is:

ld -o libXYZ.a one.o two.o -L./ -L/cygdrive/c/cygwin/lib/gcc/i686-pc-cygwin/4.8.2 -lX -lY -lZ -lstdc++ 

I'm using Cygwin GCC (g++) to compile one.cpp and two.cpp to get one.o and two.o before the ld command like the following:

g++ -o one.o one.cpp -c g++ -o one.o two.cpp -c 

libX.a, libY.a, libZ.a are all located in the current directory (that's why -L./). And I added the C++ standard library linker flag -lstdc++ in the ld line. But I got the following error when I make it:

one.o: one.cpp:(.text+0x32): undefined reference to `_Unwind_Resume' ld: one.o: bad reloc address 0xd in section `.text$_ZN10ConfigC1Ev[__ZN10ConfigC1Ev]' Makefile:22: recipe for target 'libXYZ.a' failed 

So my question is: Is the ld command the right command to build the static lib from other static libs and .o files? What caused the error? I searched the forum and found that it is possible caused by some incompatible compiler. But I built all my source code using the same GCC compiler.

UPDATE:

I tried again using the following command:

ld -o libXYZ.a one.o two.o -L./ -lX -lY -lZ 

But I'm still getting the following errors:

one.o:one.cpp:(.text+0x32): undefined reference to `_Unwind_Resume' one.o:one.cpp:(.text+0x12a): undefined reference to `_Unwind_Resume' ... ./libX.a(wrapper.o):wrapper.cpp:(.text+0x7ba): undefined reference to `__chkstk_ms' ./libX.a(wrapper.o):wrapper.cpp:(.text+0x7ba): undefined reference to `_Unwind_Resume' ... 

And I omitted numerous similar errors like the above _Unwind_Resume errors. Any ideas on what caused those errors?

2
  • This should work: stackoverflow.com/a/8170851/2298578 Commented Jun 4, 2014 at 16:52
  • Unfortunately my cygwin gcc doesn't support libtool, only ld is supported. Commented Jun 4, 2014 at 16:58

1 Answer 1

-1

So my question is: Is the ld command the right command to build the static lib from other static libs and .o files?

No. See this answer for how this can be done.

Sign up to request clarification or add additional context in comments.

2 Comments

If I use ar instead of ld command to link three static libs as the link you gave, then I need to do three ar -x commands and then one more ar -c command to link all extracted *.o object files. Is there a one-pass solution using either ar or ld to link libX.a, libY.a, libZ.a with two object files in current directory: one.o, two.o to form the new static lib libXYZ.a? IMHO using four ar commands to extract and compress libs is too cumbersome.
@tonga "using four ar commands to extract and compress libs is too cumbersome" -- don't do it by hand, write Makefile instead. A shell script wraping the ar invocations is also quite trivial to write.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.