Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!