RE: [Jail-main] Struggling with installing gcc
Brought to you by:
assman
|
From: Juan M. C. <as...@er...> - 2004-02-14 09:50:31
|
>I've been struggling with installing gcc over the past few
>weeks within a jail environment. I have a few picky web
>programmers that are writing their applets in C. I've been
>able to setup a jail environment but my success with actually
>getting a working complier has been less than satisfactory. I
>seem to be constantly fighting the missing library issue. Has
>anyone out there successfully put in a gcc complier and if so
>could you suggest a best method in doing so?
Hi Ross,
Here is a sample of how to install gcc (and the required
libraries)
Inside jail.
At the end of the mail is the jcp script :)
Installing gcc inside a jail environment
FIRST OF ALL: do the install from a newly created
Jail environment, in order to get the environment
'clean'.
example .c file:
-8<-------------------------
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
printf("hello world\n");
return(0);
}
-8<--------------------------
call this file hello.c; is our test file :)
my gcc is
# gcc --version
gcc (GCC) 3.3.2 (Debian)
maybe you are use another version, or arch,
keep it in mind an if so, replace some specific
paths to the right ones. Use your commmon sense
for that (e.g. i486-linux to ppc-linux).
The chrooted environment is called /home/testd,
with an user called testd.
Some commands are called from the non-chrooted
environment (e.g. another login session in the
machine, for example as root). This commands
are marked as #
Another commands are called from the chrooted
environment. This commands are marked as %
BEGIN------------------------------------------
1--------------------------------------
Add the gcc inside the chrooted environment
# addjailsw /home/testd -P gcc
% gcc -Wall -g -o hello hello.c
gcc: installation problem, cannot exec `cc1': No such file or directory
2--------------------------------------
copy the source to a non chrooted environment, and
extract and strace. This will allow us know what
files are required.
# cp /home/testd/home/testd/hello.c /tmp
# (strace gcc -Wall -g -o hello hello.c 2>&1) > log
then grep the log for the access files:
# grep access log |grep -v "No such"
access("/usr/bin/gcc", X_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/", X_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/", X_OK) = 0
access("hello.c", F_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/specs", R_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/", X_OK) = 0
access("/tmp", R_OK|W_OK|X_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/cc1", X_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/collect2", X_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/../../../crt1.o", R_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/../../../crti.o", R_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/crtbegin.o", R_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/crtend.o", R_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/../../../crtn.o", R_OK) = 0
access("/usr/lib/gcc-lib/i486-linux/3.3.2/collect2", X_OK) = 0
so just move them to the right place.
jcp is a python scripts that copies the file, and create
the subdirs on demand. You can find it at the end of the
mail. just copy jcp where your want and call it (i set jcp
in the same directory (./) I do the tests).
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/specs /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/../../../crtn.o /home/testd/
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/cc1 /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/collect2 /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/../../../crt1.o /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/../../../crti.o /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/crtbegin.o /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/crtend.o /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/../../../crtn.o /home/testd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/collect2 /home/tesd
# ./jcp /usr/lib/gcc-lib/i486-linux/3.3.2/collect2 /home/testd
3--------------------------------------
managing the include files
% gcc -Wall -g -o hello hello.c
hello.c:1:19: no include path in which to find stdio.h
hello.c:2:20: no include path in which to find stdlib.h
hello.c: In function `main':
hello.c:5: warning: implicit declaration of function `printf'
Just copy the include directory (the /usr/include directory)
# cp -R /usr/include /home/testd/usr
% gcc -Wall -g -o hello hello.c
In file included from hello.c:1:
/usr/include/stdio.h:34:21: stddef.h: No such file or directory
In file included from /usr/include/stdio.h:36,
from hello.c:1:
/usr/include/bits/types.h:31:20: stddef.h: No such file or directory
In file included from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from hello.c:1:
/usr/include/_G_config.h:14:20: stddef.h: No such file or directory
In file included from /usr/include/_G_config.h:24,
from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from hello.c:1:
[...more error output here]
but some "system headers" are still missing
some include files are not found ... just locate it
the files are in the gcc directory. Just copy it
# cp -R /usr/lib/gcc-lib/i486-linux /home/testd/usr/lib/gcc-lib
4--------------------------------------
including the assembler, linker
and libraries
Note that you can get a 'segmentation fault' inside the
chroot (if you are logged) due the install script overwrites
some files that are in use. Don't worry, just login again
inside the chrooted account.
4.1---the assembler
% gcc -Wall -g -o hello hello.c
gcc: installation problem, cannot exec `as': No such file or directory
install it
# addjailsw /home/testd -P as
4.2---the linker
% gcc -Wall -g -o hello hello.c
collect2: cannot find `ld'
install ld
# addjailsw /home/testd -P ld
4.2---the c lib
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
The libc is not installed ... just put them:
# ./jcp /usr/lib/libc.a /home/testd
# ./jcp /usr/lib/libc.so /home/testd
% gcc -Wall -g -o hello hello.c
/usr/bin/ld: cannot find /usr/lib/libc_nonshared.a
collect2: ld returned 1 exit status
Just install it
# ./jcp /usr/lib/libc_nonshared.a /home/testd
% gcc -Wall -g -o hello hello.c
%
% ./hello
hello world
%
you get it !
Kind Regards,
Juan M. Casillas
http://www.jmcresearch.com
Jcp script. Just copy one file to another place, making some
Directories and so on. Maybe you have to tailor the #!/usr/bin/env
python
Line in order to point the right python. Just use 2.2 or greater. Save
it
Anyware, give it execution permissions, and use it :)
--cut here
8<-------------------------------------------------------------------
#!/usr/bin/env python
########################################################################
######
#
# jcp Copy a files into the chrooted environment
# Juan M. Casillas <jua...@jm...>
#
# jcp <file> <chrooted environment path>
#
########################################################################
######
import sys
import os.path
import shutil
MODE=0755
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: %s <file> <chrooted path>" % sys.argv[0])
sys.exit(2)
fp = sys.argv[1]
chpath = sys.argv[2]
dir = os.path.dirname(fp)
fn = os.path.basename(fp)
tgt = "%s/%s" % (chpath,dir)
tgt = os.path.realpath(tgt)
if not os.path.exists(tgt):
os.makedirs(tgt,MODE)
shutil.copy(fp,tgt)
sys.exit(0)
--cut here
8<-------------------------------------------------------------------
|