Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

318
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda