Find the answer to your Linux question:
Results 1 to 7 of 7
I have a Xilinx FPGA running a soft processor (PowerPC). I recently cross compiled Boost libraries for PowerPC and wanted to test it. So I used one of the sample ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2013
    Posts
    3

    Dynamic linking failing on linux/powerpc


    I have a Xilinx FPGA running a soft processor (PowerPC). I recently cross compiled Boost libraries for PowerPC and wanted to test it. So I used one of the sample programs and tried to cross compile it for my target. Below is the code

    #include <boost/thread/thread.hpp>

    void helloworld()
    {
    printf( "Hello World!");
    }

    int main()
    {
    boost::thread thrd(&helloworld);
    thrd.join();
    }

    Below is my make file

    CPP=ppc_4xx-g++
    CFLAGS=-c -g -Wall
    LDFLAGS_PowerPC=-L/shared/deps/powerpc/lib -L/opt/ELDK/4.2/ppc_4xx/lib/
    LIBS_PowerPC=-lboost_thread -lboost_system -lpthread -lrt
    INCLUDES=-I. -I./4.2.2/ -I./include -I/opt/ELDK/4.2/ppc_4xx/usr/include/
    CPPFLAGS_PowerPC=-I/shared/deps/common/include
    CPPFLAGS_COMMON=-I/shared/deps/powerpc/include
    CPPFLAGS=$(CPPFLAGS_COMMON) $(CPPFLAGS_PowerPC)

    all: helloworld

    helloworld: helloworld.o
    $(CPP) $(LDFLAGS_PowerPC) $(LIBS_PowerPC) helloworld.o -o helloworld

    helloworld.o: helloworld.cpp
    $(CPP) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) helloworld.cpp
    clean:
    rm -rf *.o helloWorld

    I was able to generate the binaries but when I run the program on my target I get the below error

    -/bin/sh: ./helloworld: not found

    I checked online and found that the above problem comes when we have dynamic linking. My Boost libraries are present in the location /shared/deps/powerpc/lib and I have set the variable LD_LIBRARY_PATH accordingly using the below command.

    export LD_LIBRARY_PATH=/shared/deps/powerpc/lib/:/opt/ELDK/4.2/ppc_4xx/lib/

    But even then I get the same problem.

    Below is the output of uname -ars

    Linux (none) 3.0.0-14.1-build3+ #23 PREEMPT Thu Jan 3 18:44:27 CST 2013 ppc GNU/Linux

    I don't have ldd installed on my target so I can't check the dynamic dependencies. How can I install ldd to check dynamic dependencies ? But I am sure that, libraries are included. How can I proceed ?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,508
    The error isn't that it can't load shared libraries, but that the executable is not found. Are you sure there weren't any make/compiler errors in building the executable?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Apr 2013
    Posts
    3
    Yes there are no errors during the executable build. I can see the generated executable (If there are errors, the executable won't be built right ?).

    My build machine is Ubuntu and I compile using powerpc toolchain. If I try to execute the built executable in Ubuntu, I get a valid error stating that the executable can't be executed. But when I copy the executable to my target and run, it gives me the above error. So I don't think its about the binary.

    I tried one more thing. I wrote a new hello world program and used a math function. Then I statically included the math library using -lm -static flag. The executable runs on my target. But then if I remove the -static flag (allowing dynamic linking), the executable fails to run and gives the exact same error. This is why I thought the problem is with dynamic linking.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,508
    You may be correct. So either you are missing some dynamic library (or libraries), or you need to set your LD_LIBRARY_PATH environment variable to where they do exist. You mention that you don't have ldd installed on the target system. I don't suppose you may have ltrace installed? You may need to cross compile these tools with static linkage and then copy them over to the target system in order to find what the missing libraries may be. You also want to be sure you have the dynamic linker installed. That would be either ld.so and/or ld-linux.so.

    Here is a link with useful information about this subject: http://www.cyberciti.biz/tips/linux-...anagement.html
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Apr 2013
    Posts
    3
    Thanks for the reply.

    I don't have ld.so or ld.linux.so but ld-uClibc-0.9.27.so, I guess that's my loader.

    Some observations.

    I tried the command readelf on helloworld on my build machine and the below section is of our interest

    Dynamic section at offset 0xb360 contains 27 entries:
    Tag Type Name/Value
    0x00000001 (NEEDED) Shared library: [libboost_thread.so.1.53.0]
    0x00000001 (NEEDED) Shared library: [libboost_system.so.1.53.0]
    0x00000001 (NEEDED) Shared library: [libpthread.so.0]
    0x00000001 (NEEDED) Shared library: [librt.so.1]
    0x00000001 (NEEDED) Shared library: [libstdc++.so.6]
    0x00000001 (NEEDED) Shared library: [libm.so.6]
    0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
    0x00000001 (NEEDED) Shared library: [libc.so.6]

    I have 2 paths in my LD_LIBRARY_PATH

    1. /shared/deps/powerpc/lib: This has libboost_thread.so.1.53.0, libboost_system.so.1.53.0.
    2. /opt/ELDK/4.2/ppc_4xx/lib: This has the remaining libraries.

    But I am not sure if the target machine sees these libraries. The above drives are mapped on the target machine (i.e from the target shell I can reach the target library directories and see them).

    The next thing to do is check if ldd is finding some problems locating the shared libraries. You mentioned about cross compiling ldd and ldtrace statically and then try them. I searched online and I couldn't find the source files for them. can you help me find the source files for ldd and ldtrace ?
    Last edited by studywireless; 04-18-2013 at 08:32 PM.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,508
    If ld-uClibc-0.9.27.so is your shared library loader/linker, then you might try creating links from that to ld.so and ld-linux.so. If the application code is looking for one of those, sometimes creating a link will let it resolve the symbols required.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,508
    As for the sources for ldd and ltrace, they should be available on your distribution mirror sites in the source code repositories. Ditto ld.so and ld-linux.so
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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