Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
how to compile binaries in linux which can be run without preceding ./

When I compile a program using gcc it should be run using prepending ./ e.g. gcc -Wall -o hello-world hello-world.c will produce binary hello-world which i have to run it as ./hello-world But I want to run it as any other system bimary just by typing hellow-world how to compile it ?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

As a note to the answers of @BraveNewCurrency and @songziming to place the executable in the search path.

It is possible to execute the executable without adding the ./. To do that you have to add the current directory to the search path. Like this:
export PATH='./:'$PATH

This is however generally frowned upon because it can have some unintended side effects. Some people even regard it as a safety risk.
See for instance https://superuser.com/questions/156582/why-is-not-in-the-path-by-default

over 4 years ago · Santiago Trujillo Denunciar

0

You have to add the directory containing executable to $PATH to run it without ./. It has nothing to do with compilation.

Say file hello-world is located in /root/hello, you have to add it to PATH like: export PATH=$PATH:/root/hello, then you can run it with hello-world.

Linux bash commands are just executable files, you can tell the location using which:

$ which ps
/bin/ps

When you type a command without ./, bash searches all directories listed in PATH environment variable to see if it contains the executable you typed, and run it when found. On my machine, the content of PATH is:

$ echo $PATH
/opt/bochs/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/node-v5.1.1-linux-x64/bin:/opt/jdk1.8.0_65/bin:/opt/neovim/bin:/sbin:/opt/node-v5.1.1-linux-x64/bin:/opt/jdk1.8.0_65/bin
over 4 years ago · Santiago Trujillo Denunciar

0

That has nothing to do with how it's compiled. Linux only runs things that are in your $PATH. So you can copy the binary to /bin, /usr/bin, and sometimes /usr/local/bin. You can also add ~/bin to your path and put the binary there.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda