Results 1 to 5 of 5

Thread: C++ binary wont run on server if not compiled there

  1. #1
    Join Date
    Feb 2009
    Location
    47.3505, 8.71842
    Beans
    168
    Distro
    Ubuntu 11.04 Natty Narwhal

    C++ binary wont run on server if not compiled there

    Hi,

    I'm currently writing a little program in c++, that should convert some stuff for me. The app should run on my server, but I'm currently writing it on my desktop pc with eclipse. On my pc, I can execute the binary that eclipse creates by typing
    Code:
    ./Converter
    If I copy the file to my server now and type the same thing I get:
    Code:
    -bash: ./Converter: cannot execute binary file
    But if I copy the .cpp files to the server and compile them there, I can start the problem without trouble using
    Code:
    ./Converter
    Why's that and what do I have to do, so that the binary compiled on my pc works on my server?
    (My server also runs on Ubuntu).

    Cheers
    “The ships hung in the sky in much the same way that bricks don't.”
    Douglas Adams

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: C++ binary wont run on server if not compiled there

    was the file compiled with platform specific flags? (e.g. -mtune -m32 -march -msse etc .)

    do the cpu's work with the same number of bits?(32/64bit)

    to fix either do a generic compile (-march=generic -m32) or compile with gcc -v on the server and compile with the same flags on your local pc
    of course in the latter case it may not work on your local pc
    Last edited by MadCow108; August 15th, 2010 at 03:26 PM.

  3. #3
    Join Date
    Feb 2009
    Location
    47.3505, 8.71842
    Beans
    168
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: C++ binary wont run on server if not compiled there

    Thank you for your quick answer!

    Quote Originally Posted by MadCow108 View Post
    was the file compiled with platform specific flags? (e.g. -mtune -m32 -march -msse etc .)
    I dont know about eclipse, I just used the "build" command. I have no idea if it does set some flags. On the server I used g++ and didnt set any flags.
    do the cpu's work with the same number of bits?(32/64bit)
    No, my server is 32bit and my pc is 64bit

    to fix either do a generic compile (-march=generic -m32)
    How would I do that with eclipse?


    Cheers
    “The ships hung in the sky in much the same way that bricks don't.”
    Douglas Adams

  4. #4
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: C++ binary wont run on server if not compiled there

    Quote Originally Posted by Zilioum View Post
    No, my server is 32bit and my pc is 64bit
    Here's the problem.
    gcc by default compiles files for the wordwidth of the local machine.
    So you compile 64 bit executables on your pc, which do not work on an 32 bit system.

    You have to explicitly compile 32 bit executables with the -m32 flag (I do not know how to get eclipse to do thats)
    you may also need to install 32 bit libraries on your 64 bit system:
    sudo apt-get install ia32-libs gcc-multilib g++-multilib

  5. #5
    Join Date
    Feb 2009
    Location
    47.3505, 8.71842
    Beans
    168
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: C++ binary wont run on server if not compiled there

    Yeah, of course, that makes sense. Will try that out.
    Thanks a lot for your help!

    Cheers
    “The ships hung in the sky in much the same way that bricks don't.”
    Douglas Adams

Tags for this Thread

Bookmarks

Posting Permissions

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