Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How to build a statically linked appl with PIC enabled static library?


    I've a statically linked application (sample.a) and I want to build it with a third party library(third-party-lib.a) which is PIC enabled. Note that the third party library is NOT a shared library. It is a PIC enabled static library.

    Can anyone please suggest how do I do this?

    I tried linking my library with a third party library like we usually link static libraries but it gives me an error:

    /usr/lib/libc_nonshared.a(stack_chk_fail_local.oS): In function `__stack_chk_fail_local':
    (.text+0x10): undefined reference to `__stack_chk_fail'

    Thanks in advance.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    A word of advice - ALWAYS build your code with PIC enabled. I have run into this problem so many times in the past (linking PIC-enabled libraries with non-PIC-enabled ones) that this is now a rule in every organization I have worked that. What PIC does is make your functions and variables relocatable - necessary for shared libraries, but useful for mixed-mode situations such as yours. If you cannot recompile your own libraries with PIC enabled, then I think you are SOL...

    Anyway, since you aren't providing any specific compiler/linker command lines that you are using, this is the best advice I can provide.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    1. Were you getting the same error that I'm getting? One school of thought says that it shouldn't matter whether it is PIC enabled or not. So I'm in a fix now. Please let me know whether the error message is same as the one you were getting.

    2. I've noticed one more thing. This problem doesn't occur when I compile with with my usr/bin's gcc. The gcc we use in our toolchain is of older version and with that gcc I face this problem. I can't build all of my source code with the gcc in user/bin at the moment due to various other factors.

    Here's where it fails during build:

    ### lmutil [2012-06-05 03:57:58 GMT]
    make: Entering directory `/data/home2/vineet/vvinod_main/flexnet/utils/build/_debug-Linux-ipv4.LSB_3.0-i686-main'
    make: Warning: File `Makefile' has modification time 2.5e+04 s in the future
    [LD] lmutil
    lsbcc -o lmutil.debug -D_DEBUG -ggdb -O0 -m32 -march=pentium -pipe -DARCH_INTEL -DARCH_X86 -DOS_LINUX -pthread -DLM_INTERNAL -DFLEXLM_KITBUILD -DFLEX_STATIC -DGPLATFORM="i86_lsb" -DLINUX -DLSB3_0 -D__FD_SETSIZE=65535 -DGLIBC -DX86 -DREDHAT -DREL -DPLATFORM_X86_RHLINUX -fvisibility-inlines-hidden -D_GLIBCXX_DEBUG -Wl,--dynamic-linker=/lib/ -nodefaultlibs -Wl,--dynamic-linker=/lib/ --lsb-besteffort --lsb-target-version=3.0 ../../lib/_debug-Linux-ipv4.LSB_3.0-i686-main/liblmutil.a ../../../src/build/_debug-Linux-ipv4.LSB_3.0-i686-main-mt_nopic/liblmgr.a ../../../../flexnet/src/dongle/_debug-Linux-ipv4.LSB_3.0-i686-main/dongle.a ../../../../3rdparty/cert/lib/Linux_LSB_3.0_i686/libcrvs.a ../../../../3rdparty/cert/lib/Linux_LSB_3.0_i686/libsb.a ../../../../FNP/_output/_debug/fnp-i86_lsb- -L /v/toolchain/Linux-LSB_3.0-i686/lib -Wl,-dn -lstdc++ -Wl,-dy -lpthread -lm -lgcc -lgcc_s -lc -ldl
    /usr/lib/libc_nonshared.a(stack_chk_fail_local.oS): In function `__stack_chk_fail_local':
    (.text+0x10): undefined reference to `__stack_chk_fail'
    collect2: ld returned 1 exit status

    Please let me know your opinion.


  4. $spacer_open
  5. #4
    Also, this is how I merge the third party PC enabled static libraries:
    <postlink cmd="armerge dongle$(LIB_SUFFIX)$(AREXTENSION) dongle$(LIB_SUFFIX)$(AREXTENSION) ../../libs/linux/libhasplnx350.a" system="Linux" architecture="i686" subvariant="!mt_pic" />

    <postlink cmd="armerge dongle$(LIB_SUFFIX)$(AREXTENSION) dongle$(LIB_SUFFIX)$(AREXTENSION) ../../libs/linux/libhasplnx120_x64.a" system="Linux" architecture="x86_64" subvariant="!mt_pic" />

    libhasplnx350.a and and libhasplnx120_x64.a are the libraries.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts