Thread: Using code compiled in OpenSUSE on a microcontroller running Gentoo Linux

  1. #16
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    By statically compile the code, I mean link it statically. If you look up several topics, this was a suggestion given by matsp to avoid any conflicts between the operating system that I am using on my desktop, which is openSUSE, and the operating system running on the PC104, which is a copy of Gentoo Linux.

    From what I have been doing, it seems like the libcxcore libraries on the two systems are incompatible. So a dynamically linked program compiled on one machine using opencv will not work on the other.

    I have tried statically linking the code using -static, only to get an error saying that libcxcore could not be located. So, I went back to the copy of opencv 1.0.0 that I obtained from sourceforge.net, gave a /configure --enable-static instruction that told make the statically link the opencv libraries after compiling, then ran make clean, make, and make install.

    The result installed things like libcxcore.a onto Linux, allowing my program to recognize opencv when I statically linked it. Unfortunately, it now would not recognize several other things, including libdc1394. libraw1394, and gtk. I have libdc1394 and libraw1394 source code from sourceforge.net, so I can just do the same thing I did with them that I did with opencv. Unfortunately, gtk either came with the Linux install or was installed through YaST as a dependacy, and I lack the source code to do the same with it.

  2. #17
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Phanixis View Post
    The result installed things like libcxcore.a onto Linux, allowing my program to recognize opencv when I statically linked it. Unfortunately, it now would not recognize several other things, including libdc1394. libraw1394, and gtk. I have libdc1394 and libraw1394 source code from sourceforge.net, so I can just do the same thing I did with them that I did with opencv. Unfortunately, gtk either came with the Linux install or was installed through YaST as a dependacy, and I lack the source code to do the same with it.
    If you give the -static option to the linker, it has to link EVERYTHING statically. If you want to try linking only CERTAIN libraries statically, just list their archives on the link line as if they were object files instead of linking with the "-l" flag:

    Code:
    gcc -o program -lsomething -lsomething_else /path/to/libcxcore.a
    That links cxcore statically, the other stuff dynamically (if possible). If you really want a fully static link, there are ways to "massage" a shared library to turn it into a static library, without recompiling everything.

    EDIT: Off the top of my head, I'm not remembering how to do what I just said. I might be hallucinating, although it seems it should be possible. I'll keep looking at it..
    Last edited by brewbuck; 10-19-2007 at 04:30 PM.

  3. #18
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    That is an incredibly helpful suggestion. This will definitely make my life easier.

    Thanks.

  4. #19
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Phanixis View Post
    That is an incredibly helpful suggestion. This will definitely make my life easier.

    Thanks.
    I wasn't hallucinating! There is a project called "ELF Statifier" which takes a dynamically linked binary and turns it into a static image. So if all you have are dynamic libs, and you want to produce a static executable, this might allow you to do it.

  5. #20
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    I will have to try that program.

    In the mean time, I tried your suggestion of statically linking only the library components that were giving me problems. In this case, the PC-104 is saying that it cannot find the library libcxcore.so.1. So I gave make the instructions /usr/local/lib/libcxcore.a and /usr/local/libcxcore.so.1 for the linking stage, but it has not corrected the situation.

  6. #21
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    I tried out Elf Statifier, it looks a good program but the instructions don't seem to be very thorough. I tried creating an executable using this program, only to get a "Failed to read a valid object file image from memory." message, and executable it creates immediately produces a segmentation fault when I run it. I could really use some troubleshooting documentation for this thing.

  7. #22
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    It's strange. I never saw statifier faled like this.

    Could you please post your problem to statifier's forum
    https://sourceforge.net/forum/forum.php?forum_id=358807
    with following details:
    statifier's version
    gdb version
    your distro
    kernel version
    platform (x86/x86_64)
    output of
    statifier -v orig_program statified_program

    Valery.
    P.S. you can also try ermine (http://magicErmine.com)

  8. #23
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    Ok, I will do that. Only problem is that I will not be able to fit the verbose output on a forum post, because it is that long.

  9. #24
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Never mind, "Failed to read a valid object file image from memory"
    provide enough information.

    I found this bug report
    https://bugzilla.novell.com/show_bug.cgi?id=258433

    and I'll try to work around it.

    Valery.

  10. #25
    Registered User
    Join Date
    Oct 2007
    Posts
    33
    Ok, I have yet to get Statifier working, but I tried Ermine and it was able to compile the file I need without giving any explicit error messages.

    However, I get the error: Bad File Descriptor(9) when I run the executable on the PC-104.

    Any idea why?

    Thanks.

  11. #26
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Phanixis View Post
    Ok, I have yet to get Statifier working, but I tried Ermine and it was able to compile the file I need without giving any explicit error messages.

    However, I get the error: Bad File Descriptor(9) when I run the executable on the PC-104.

    Any idea why?

    Thanks.
    Try using "strace" to see where it's going wrong. [You may want to use "strace app 2> blah.txt" - as seeing the last 20 or so lines usually just show you that it printed an error message and some cleanup, rather than what actually went wrong]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #27
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Quote Originally Posted by Phanixis View Post
    Ok, I have yet to get Statifier working, but I tried Ermine and it was able to compile the file I need without giving any explicit error messages.

    However, I get the error: Bad File Descriptor(9) when I run the executable on the PC-104.

    Any idea why?

    Thanks.
    Did you get same error when you run packed executable on the openSUSE system ?
    Could you send output of
    1) ldd your_program
    2) ERMINE_SELF_LOG_MASK=1 your_program.ermine

    Valery

  13. #28
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    But, first, you should take a step back and ensure that you _can_ write a binary that will execute on the other machine. Are you SURE that you are working with an x86? Have you attempted to compile a "Hello World" on the build machine for the host? If you cannot do this, then you start over from scratch with BuildRoot or crosstools.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  2. running code in borland
    By Aisthesis in forum Tech Board
    Replies: 5
    Last Post: 05-19-2009, 12:06 AM
  3. Problems running compiled .exe on other machines.
    By Troels Leth in forum C++ Programming
    Replies: 39
    Last Post: 05-09-2008, 05:30 AM
  4. Problem in running turbo C code
    By bulogi in forum C Programming
    Replies: 6
    Last Post: 04-26-2008, 10:25 PM
  5. code to run (linux) programs WITH arguments
    By N8760 in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 03:35 PM