Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm playing around with chroot environments, and I'd like to have a portable C compiler so that I can easily set up some basic build-tools in each environment without having to move too many libraries around.

Gcc seems pretty bloaty for what I want to do, but if it's reasonably easy to build a static gcc I wouldn't mind a few dozen megabytes.

I am also looking at the Tiny C Compiler, which is smaller but still looks like it's got an impressive feature set. However, running ./configure --help in the source directory doesn't list any option for building tcc statically, and I'm not sure how it might be done otherwise.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Building a static binary should be as simple as running gcc with -static, or if ld is being called directly use -Bstatic. Try

CFLAGS=-static make

after running configure. If it fails, the results will be obvious, e.g. rafts of undefined references at link time.

share|improve this answer
    
I tried make CFLAGS=-static just now. Make prints some warning about dlopen, then when I try to run the executable in the chroot environment, I get /usr/lib/crt1.o .. crti,o .. crtn.o not found errors. Is that what you meant by "undefined references at link time"? –  math4tots Feb 18 '12 at 0:56
    
The errors I expected would have been due to missing static versions of libraries, like crt1.o, but the linker would complain immediately. If you're seeing the errors at runtime, then the binary wasn't staticly linked. –  Kyle Jones Feb 18 '12 at 0:59
    
I think you misunderstood the question: math4tots wants a C compiler that works as a standalone binary (or at least as an easily-identifiable set of files) not a C compiler that produces standalone binaries. –  Gilles Feb 18 '12 at 23:31
    
Yes, I understand that. Producing a staticly linked compiler is a necessary first step, and one that the question seems to be asking about. –  Kyle Jones Feb 19 '12 at 0:44
    
@Gilles The best way to get a C compiler as a standalone binary is to build it from source using a complier you already have. –  OrangeDog Aug 14 '12 at 15:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.