How to build C program with b2 without libstdc++ dependency?

138 views Asked by At

I have a simple C program and such jamroot.jam:

exe hello : hello.c ;

I can run b2 -d+2:

........
gcc.compile.c bin/gcc-8.3.0/debug/hello.o

    "g++" -x c -fPIC -O0 -fno-inline -Wall -g     -c -o "bin/gcc-8.3.0/debug/hello.o" "hello.c"

gcc.link bin/gcc-8.3.0/debug/hello

    "g++"    -o "bin/gcc-8.3.0/debug/hello" -Wl,--start-group "bin/gcc-8.3.0/debug/hello.o"  -Wl,-Bstatic  -Wl,-Bdynamic  -Wl,--end-group -fPIC -g
........

After this I receive hello binary which depends on libstdc++:

$ ldd bin/gcc-8.3.0/debug/hello
        linux-vdso.so.1 (0x00007fffdaf5b000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff6d8176000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff6d7ff3000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff6d7fd9000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff6d7e18000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff6d8329000)

If I build it with gcc I get much less dependencies:

$ gcc hello.c -o hello
$ ldd ./hello
        linux-vdso.so.1 (0x00007ffc661cc000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca20243000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fca20433000)

Can I do this with b2?

I have a project which includes C and C++ programs and I would not like to have different build system for C binaries.

1

There are 1 answers

3
AudioBubble On

Try using g++, it works for c++ and c it should work for compiling, when you're done compiling run ./filename