Static link to libpthread

I’m trying to port an application that I made for the old Connect-ME and LxNETETES to the new CME 9210 with ESP Linux. As for the old platform, this application is statically linked against libpthread.a as it uses threads. The build process gives no errors and the app seems to statically link to other libs located in the general lib folder (libm, and other custom libs). Nevertheless, when I run the application on my CME 9210 Dev kit I get this error:

can’t load library ‘libpthread.so.0’

What does this mean? Is the application trying to load libpthread dynamically??

Thanks in advance for your help and ideas.

Daniel.

I’ve verified that any application linking to libpthread.a (link option -lpthread) generates this error at runtime:

can’t load library ‘libpthread.so.0’

Same result for the application template pthread_test.

Any light on this issue is welcome.

Thanks again,

Daniel.

Please include pthread example in to you rootfs/kernel project it will then automatically add stripped version of the library you need.

Hello Daniel!

  1. add your own pthread application to:
    workspace/yourproject/build/apps/my_pthread/*
    Just copy /usr/local/DigiEL-4.2/apps/pthread_test_c/Makefile into this directory, modify it to compile your sources and copy your source there.

Note: Don’t copy the Kconfig into your app!!

The line “LDFLAGS=-pthread” in the Makefile is responsible that some upper layer makefile which is called when you build the rootfs, is automatically copying the libpthreadso to your rootfs.
=> you don’t need to include the pthread example application, to get the library added to your rootfs. The build system does itself find that your application needs the lib and will deploy it to the rootfs.

  1. If you want your application not to use the dynamic library linked during runtime, you should change your Makefile to:
    LDFLAGS = -static -strip -pthread
    where “-strip” is optional, just to save flash space.

I tested this and for (3) you will not have libpthreadso inside your rootfs!

Thomas.

Thank you very much,

I’ve just tested LeonidM’s method and it works. I’m now going to try with your way, Thomas.

Thanks again,

Daniel.

Linking with -static works fine.

Thanks again.