Reputation: 121387
I have installed gcc-7.1.0 from source based on: https://gcc.gnu.org/install/index.html to use a newer gcc.
The compiled binaries have an extra dependency with libgcc
:
$ ldd a.out
linux-vdso.so.1 => (0x00007fffd85fd000)
librt.so.1 => /lib64/librt.so.1 (0x000000365b400000)
libdl.so.2 => /lib64/libdl.so.2 (0x000000365a800000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000301ae00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000365b000000)
libc.so.6 => /lib64/libc.so.6 (0x000000365a000000)
/lib64/ld-linux-x86-64.so.2 (0x0000003659c00000)
I didn't choose any particular configuration options (other than --prefix
) and installed with defaults. Looking at the config.log
, it appears that configuration decided it couldn't do so by default. Relevant parts:
configure:5038: checking whether g++ accepts -static-libstdc++ -static-libgcc
configure:5055: g++ -o conftest -g -O2 -static-libstdc++ -static-libgcc conftest.cpp >&5
g++: unrecognized option '-static-libstdc++'
conftest.cpp:11:2: error: #error -static-libstdc++ not implemented
configure:5055: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h. */
|
| #if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
| #error -static-libstdc++ not implemented
| #endif
| int main() {}
configure:5059: result: no
(The g++
available - used above - is a bit old: g++ 4.1.2 if that's relevant).
I am compiling only C code. So, if there's no static linking support -static-libstdc++
, that's not an issue. But I don't understand why libgcc
is tied with -static-libstdc++
.
libgcc_s.so.1
isn't always available on all machines. While I can install it, I don't want this extra requirement on my customers. Is there any way I can remove this dependency?
While using -static-libgcc
switch does get remove libgcc_s.so.1
, I am looking for a way to let gcc itself do this. If that means re-configuring and reinstalling gcc, it is fine by me.
P.S.: I also have to follow the workarounds from here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61955 as the machine is a bit old.
Upvotes: 3
Views: 4056
Reputation: 171263
But I don't understand why libgcc is tied with -static-libstdc++.
It isn't. That configure test controls whether the intermediate compiler during bootstrap is linked statically or dynamically, it has nothing to do with the executables produced by the final GCC.
libgcc_s.so.1
isn't always available on all machines. While I can install it, I don't want this extra requirement on my customers. Is there any way I can remove this dependency?
IMHO it should be installed anyway, lots of packages depend on it.
The executables depend on libgcc because they use something from that library. Link with -static-libgcc
to use libgcc.a
instead of libgcc_s.so
. If you want that to happen automatically either install a wrapper script around your new GCC that always adds it to the command-line arguments, or use a custom specs file that always adds that option, e.g. by configuring GCC with something like:
--with-specs=%{!shared-libgcc:-static-libgcc}
This should mean that -static-libgcc
is always used implicitly unless -shared-libgcc
is explicitly provided on the command line. I haven't tested it though.
Upvotes: 5
Reputation: 5899
gcc-7.1.0 depends on libgcc_s.so.1 (Or the static), version 7.1.0, which must be supplied with the "gcc-7.1.0 package".
Easily done when gcc is supplied as a self contained folder. (gcc7/) Which is often the most convenient solution for an extra compiler.
Ref. http://www.linuxfromscratch.org/lfs/view/development/ → → http://www.linuxfromscratch.org/lfs/view/development/chapter05/gcc-pass2.html (The LFS method is recommended by the gcc people.)
Example, --prefix=/opt/gcc7 or --prefix=/usr/localgcc7
../gcc-7.1.0/configure --prefix=/opt/gcc7 --program-suffix=7 --enable-languages=c,c++ --disable-multilib
Making the links : cd /usr/bin/ && ln -s [path-to]/gcc7/bin/gcc7 && ln -s [path-to]/gcc7/bin/g++7
Also very easy to create a package.deb, package.rpm from the above.
? Who would want to be without a c++ compiler ? Suggest: Include g++.
Upvotes: -3