3picide wrote:Thanks so much. That worked. Any tips (other than using a normal account) for a newcomer to Linux? I figured out how to install programs (believe me, that was a struggle lol). Well, I do have one specific question: what would be considered the executable file for Linux? I have a KDevelop for C++, but I'm not really sure what I'm compiling it into. I'm reading a tutorial on it, but it didn't really explain what each step actually did.
Unix doesn't use extensions like DOS/Windows does. Files are either executable or they're not. We use the
chmod command to set the "executability" of a file.
https://www.cs.drexel.edu/cgi-bin/manServer.pl/chmod.1 or you can just type
man chmod from a terminal window to see the built-in help pages.
Sidetrack
The
ls -al command from a terminal window will print a directory listing that includes the permissions for user,group,other, showing read,write,execute.
- Code: Select all
[paulp@localhost ~]$ cd /bin
[paulp@localhost bin]$ ls -al
total 7136
drwxr-xr-x 2 root root 4096 Feb 16 16:14 .
drwxr-xr-x 23 root root 4096 Mar 17 14:33 ..
-rwxr-xr-x 1 root root 6268 May 24 2008 alsacard
-rwxr-xr-x 1 root root 18772 May 24 2008 alsaunmute
-rwxr-xr-x 1 root root 4988 May 24 2008 arch
lrwxrwxrwx 1 root root 4 Feb 4 10:21 awk -> gawk
-rwxr-xr-x 1 root root 18484 May 24 2008 basename
-rwxr-xr-x 1 root root 735004 May 24 2008 bash
-rwxr-xr-x 1 root root 23132 May 24 2008 cat
-rwxr-xr-x 1 root root 41828 May 24 2008 chgrp
See those rwx's at the far left? That's the read ("r"), write ("w") and/or execute ("x") flag. Unix also keeps track of file permissions for user, group and others. So - the r,w,x are clumped in groups of three - user rwx, group rwx, and other rwx. The first letter designates whether the directory entry is another directory ("d") or a symbolic link to another file ("l")
ahem - okay - sidetrack over
So - yes - you would use C++ to compile a file. But - the final file would just be a name.
Here's an example Hello World program in plain vanilla C:
- Code: Select all
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
You can use gedit or nano to create this file. Call it "hello.c" - the .c is added for our convenience - Unix doesn't care what the actual ending is. Now, from a terminal window, you can compile it thusly:
gcc -o hello32 -m32 hello.cand for 64 bit
gcc -o hello64 -m64 hello.cThese commands will generate two executables - hello32 and hello64. To run them, you'd just type the full path to the executable - or do it the Unix way which is to use the "." as a macro for current path.
So - that would be - from a terminal window in the same directory as the binary:
./hello32 and
./hello64You can use the
file command to tell you more about any file. Here's the output from my PS3:
- Code: Select all
[paulp@yurie test]$ gcc -o hello32 -m32 hello.c
[paulp@yurie test]$ file hello32
hello32: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
[paulp@yurie test]$ gcc -o hello64 -m64 hello.c
[paulp@yurie test]$ file hello64
hello64: ELF 64-bit MSB executable, cisco 7500, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
[paulp@yurie test]$
There's more about Unix executables here:
http://en.wikipedia.org/wiki/Executableincluding the format the Linux uses:
http://en.wikipedia.org/wiki/Executable ... ble_FormatCheers,
Paul