Executable says "line 1: ELF: not found" when starts

14,977

Solution 1

Apparently your target system either doesn't support executing ELF files, or doesn't recognize your file as an ELF file.

When you execute a file on a UNIX-like system, it will be executed directly if the kernel recognizes it as an executable format. If not, if there's no #! line at the top, it will try to execute it as a shell script using /bin/sh. It's a binary file, but there's no really firm distinction between binary and text files.

The shell apparently tried to interpret the beginning of the file (which includes the characters ELF) as a command, and wasn't able to find that command in $PATH.

You'll need to find a way to generate an executable file that your target system will recognize and accept. (I don't know how to do that.)

Solution 2

In addition to other answers here, there might be simple cause for "line 1: ELF: not found, line 2: syntax error: unexpected "("":

You are running a 64-bit program on a 32-bit machine. Try changing your compiling config.

Solution 3

Did you remember to change the file property to make it executable?

chmod +x filename

I know I often forget this step when I download something (usually an installation binary). Just a thought!

Share:
14,977
neshkeev
Author by

neshkeev

I am employed as a java software engineer. My interests are foundation of mathematics, the category theory and lambda calculus. I am programming languages agnostic

Updated on June 15, 2022

Comments

  • neshkeev
    neshkeev almost 2 years

    I try to build a simple hello, world ELF for my router Xiaomi Router 3g with cmake. It runs

    Linux OpenWrt 4.14.95 #0 SMP Wed Jan 30 12:21:02 2019 mips GNU/Linux
    

    I use the sdk for ramips platform (my router's platform).

    The idea is to use $(PKG_BUILD_DIR) as a directory to perform an external build (which is usually done via mkdir build ; cd build ; cmake ..)

    The build finishes successfully and when I install it on my router and start it, it fails with:

    root@OpenWrt:~# chw
    /usr/bin/chw: line 1: ELF: not found
    /usr/bin/chw: line 2: syntax error: unexpected "("
    

    When I build the ELF without cmake (

    1. comment out the line include $(INCLUDE_DIR)/cmake.mk,
    2. uncomment the $(CP) ... line in the define Build/Prepare section
    3. eliminate the define Build/Compile section

    ), it works just fine: it prints Hello, World!.

    Log file is here, .config file is here

    The source code is available here

    Here is the source code:

    main.c:

    #include <stdio.h>
    
    int main()
    {
        printf("Hello, World!");
        return 0;
    }
    
    

    CMakeLists.txt:

    cmake_minimum_required (VERSION 2.6)
    
    project (chw)
    
    add_executable(chw main.c)
    
    install(TARGETS chw DESTINATION /usr/bin)
    

    Makefile:

    include $(TOPDIR)/rules.mk
    
    PKG_NAME:=chw
    PKG_VERSION:=0.1
    PKG_RELEASE:=1
    
    PKG_MAINTAINER:=John Doe <[email protected]>
    PKG_LICENSE:=CC0-1.0
    
    include $(INCLUDE_DIR)/package.mk
    include $(INCLUDE_DIR)/cmake.mk
    
    define Package/chw
        SECTION:=utils
        CATEGORY:=Utilities
        TITLE:=Hello world application
        URL:=https://www.example.com
    endef
    
    define Package/chw/description
        hello world application
    endef
    
    define Build/Prepare
        mkdir -p $(PKG_BUILD_DIR)
        # $(CP) ./src/{main.c,Makefile} $(PKG_BUILD_DIR)/
    endef
    
    define Build/Configure
        cmake -B $(PKG_BUILD_DIR) -S ./src
    endef
    
    define Build/Compile
        $(call Build/Compile/Default,-C $(PKG_BUILD_DIR))
    endef
    
    define Package/chw/install
        $(INSTALL_DIR) $(1)/usr/bin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/chw $(1)/usr/bin/
    endef
    
    $(eval $(call BuildPackage,chw))
    
  • Nick Chan Abdullah
    Nick Chan Abdullah about 3 years
    this is exactly what I encountered with my .net core program on debian. thanks
  • Marcello de Sales
    Marcello de Sales about 2 years
    Saved me while implementing a docker image for python!
  • Keith Thompson
    Keith Thompson about 2 years
    That wouldn't cause that particular error message.