I am trying to debug gcov code. I wrote a simple C program which calls __gcov_flush() method which is part of gcc/gcov.
After confirming that libgcov.a library has not been built with debug symbols, I have installed debuginfo packages for gcc on my machine (SLES 10).
# gcc -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.1.2 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib64 --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --program-suffix= --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=x86_64-suse-linux
Thread model: posix
gcc version 4.1.2 20070115 (SUSE Linux)
# rpm -qi gcc-debuginfo-4.1.2_20070115-0.29.6.x86_64
Name : gcc-debuginfo Relocations: (not relocatable)
Version : 4.1.2_20070115 Vendor: SUSE LINUX Products GmbH, Nuernberg, Germany
Release : 0.29.6 Build Date: Sat Sep 5 03:04:50 2009
Install Date: Thu Apr 24 05:25:32 2014 Build Host: bingen
Group : Development/Debug Source RPM: gcc-4.1.2_20070115-0.29.6.src.rpm
Size : 251823743 License: GPL v2 or later
Signature : DSA/SHA1, Sat Sep 5 03:06:59 2009, Key ID a84edae89c800aca
Packager : http://bugs.opensuse.org
URL : http://gcc.gnu.org/
Summary : Debug information for package gcc
Description :
This package provides debug information for package gcc.
Debug information is useful when developing applications that use this
package or when debugging this package.
Distribution: SUSE Linux Enterprise 10
/usr/lib/debug/usr/bin # ls -lrt gcov.debug
-rw-r--r-- 1 root root 94216 Sep 5 2009 gcov.debug
However, even after installing the proper version of debuginfo (gcov.debug) packages, GDB still cannot recognize the line number information, it just passes the control to next line without reporting line number (or stepping into the function).
(gdb)s
26 i++;
(gdb)s
27 __gcov_flush();
(gdb)s
28 printf("%d",i);
(gdb)
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".
Why GDB cannot identify line number information for gcov? If I have not installed the proper version of debuginfo packages for gcc/gcov, How to confirm it?
After confirming that libgcov.a library has not been built with debug symbols, I have installed debuginfo packages
You don't appear to understand how debuginfo packages work. They can't magically add debuginfo to an archive library that was built without debug symbols (or one that was stripped).
The usual build flow is:
build everything with -g
prepare separate debuginfo packages for all fully-linked binaries (executables and shared libraries)
strip fully-linked binaries (but not archive libraries)
This allows binaries and shared libraries to be small, but still debuggable after installing the debuginfo package.
Apparently, on SLES10 the "but not archive libraries" was not honored, and libgcov.a got stripped as well. Since separate debuginfo packages do not work for archive libraries, you can't get that info back. Your only option is to rebuild GCC from sources.
P.S. Why would they strip libgcov.a?
It's a trade-off: binaries that end-users link will be smaller, but code in libgcov.a will not be debuggable.
Since most end-users never debug libgcov.a, I'd say it was not an unreasonable trade-off.
Related
I installed FreeBSD 12.2 on my server with an amd64 kernel. I tried to compile my source which was created for an i386 system. And I get this error:
skipping incompatible /usr/local/lib/gcc9/gcc/x86_64-portbld-freebsd12.3/9.5.0/../../../libstdc++.a when searching for -lstdc++
I thought its beacuse I need the shared i386 lib libaries and I was searching how to install them. Just have found to install it over "bsdinstall" which doesnt work on my root or to unpack a .tgz file which isnt in my system either.
1.You have to check if your package (lang/gcc9) was compiled with the option multilib=ON using pkg info gcc9 and see in the Options section. If not, you have to do this from the ports tree /usr/ports/lang/gcc9 :
$ sudo make config
(set 'Multilib' option to ON)
$ sudo make
$ sudo make install clean
or as root (one shot, as you wish ...):
# make config install clean
FYI, FreeBSD has 32bits support by default, see /usr/lib32 and do not forget to check if you include this directory when building your project.
Some infos:
on the package : FreshPorts - lang/gcc9
How to Install Applications: Chapter 4 - Installing Applications Packages and Ports
Plz Check/read these docs before proceeding.
2.If you have installed/compiled gcc9 with multilib option set to ON, troubles come from your environment (IDE, missing paths from the compiler options, etc...).
EDIT: just checking my own compiler, I forgot to mention gcc/g++ could report whether it was compiled with multilib support or not, using the preproc builtins information (see --enable-multilib below), you could use the following eg:
$ g++ -m32 -E -P -v -dD
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-portbld-freebsd13.0
Configured with: /wrkdirs/usr/ports/lang/gcc11/work/gcc-11.3.0/configure --enable-multilib --with-build-config=bootstrap-lto-noplugin --disable-nls --enable-gnu-indirect-function --enable-host-shared --enable-plugin --libdir=/usr/local/lib/gcc11 --libexecdir=/usr/local/libexec/gcc11 --program-suffix=11 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc11/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --without-zstd --enable-languages=c,c++,objc,fortran,jit --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/share/info/gcc11 --build=x86_64-portbld-freebsd13.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.0 (FreeBSD Ports Collection)
I have MSYS2 64 bit installed in my system.
When I try to check the gcc version, I am getting the following output.
$ gcc --version
gcc.exe (Rev9, Built by MSYS2 project) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
But I want to use a specific mingw version for my project which uses qt library.
When I check my build log and installation folder of my qt project I found this.
|Project name: DataManager
|Project version: undefined
|C++ compiler for the host machine: ccache c++ (gcc 4.9.2 "c++ (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 4.9.2")
|C++ linker for the host machine: c++ ld.bfd 2.24
|Program python3 found: YES
|Found qmake: C:\Qt\5.6.3\mingw49_32\bin\qmake.EXE (5.6.3)
I am assuming that it uses mingw49_32 version and gcc version 4.9.2.
I would like to use the same gcc version (4.9.2) in MSYS2.
How can I achieve it ?
You can't do that with MSYS2. Old packages are eventually removed from MSYS2 repos, so even if it had GCC 4.9 at some point in the past, it no longer does. The earliest available version is GCC 9.3.
Even if it was in the repo, you'd have to manually download and install it and all its dependencies, since there's no way to download outdated packages directly from pacman.
But, I suspect that:
You already have GCC 4.9 installed in C:\Qt\5.6.3\mingw49_32\bin.
Even if you don't, you might be able to get away with using an up-to-date GCC.
I have installed cygwin on my Windows 7 platform. I now wish to access gcc. When I type man gcc, there is no gcc. When I search the downloaded folder for cygwin, I have a folder cygwin\x86_64\release\gcc and two other folders libgcc1 and libstdc++6; each folder has a tar file.
How do I install gcc please?
The instruction for the usage of cygwin setup are here:
https://cygwin.com/cygwin-ug-net/setup-net.html#setup-packages
By default the setup installs only the packages in the Base Category, that are 36
plus some libraries needed by them.
Any of the remaining ~ 8000 packages must be installed directly or could come as dependency of installed packages.
The package that contains the gcc compiler can be found with cygcheck
$ cygcheck -p bin/gcc.exe
Found 6 matches for bin/gcc.exe
gcc-core-7.3.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-7.3.0-2 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-7.3.0-3 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-debuginfo-7.3.0-1 - gcc-debuginfo: Debug info for gcc
gcc-debuginfo-7.3.0-2 - gcc-debuginfo: Debug info for gcc
gcc-debuginfo-7.3.0-3 - gcc-debuginfo: Debug info for gcc
so you need to install gcc-core
Working with embedded C-projects. There are libraries, include files and so on - for micro controllers. No need for me to use GCC for a host machine and OS (Linux Mint 64 bit). As a rule...
But now I'm trying to compile mspdebug project from a Github - with a GCC of course. And I get an error at the very begin of make:
mspdebug$ make
cc -DUSE_READLINE -O1 -Wall -Wno-char-subscripts -ggdb -I. -Isimio -Iformats -Itransport -Idrivers -Iutil -Iui -DLIB_DIR=\"/usr/local/lib/\" -o util/btree.o -c util/btree.c
util/btree.c:19:20: fatal error: assert.h: No such file or directory
#include <assert.h>
^
compilation terminated.
I search for the includes in all possible paths (I've got the list of them via gcc -v command) - there are no assert.h file, as well, as stdio.h and so on. Except virtual box directories there is only one place (where GCC does not search includes): /usr/lib/syslinux/com32/include
AFAIK, all standard libs and includes are installed with the GCC. So I try to reinstall GCC (4.8.4) - nothing changes.
What is the normal way to give GCC all standard environment it needs?
Thanks to the right direction set by Sam Varshavchik I found the info in the stackoverflow. So I did the following:
1) installed build-essential:
sudo apt-get install build-essential
2) installed libusb (since my try to build the package revealed the absence of usb.h):
sudo apt-get install libusb-dev
And it is OK! The mspdebug (v.023) is compiled and successfully tested!
So, Linux Mint 17.2 (at least) requires installing some libs to a GCC, the most basic is build-essential.
assert.h is not part of gcc, it's a part of glibc.
Most likely, your Linux distribution puts the system headers into a separate package that you need to install.
Fedora, for examples, puts the header files in the glibc-headers package. However, you can't be using Fedora, because Fedora's gcc package has a dependency on glibc-headers, to make sure that it gets pulled in.
Whatever Linux distribution you're using, you need to research which distribution package will install the system header files you need to build stuff with.
I have a c++11 library ( https://github.com/matiu2/cdnalizer ). I want to distribute it on centos6 and ubuntu12.04 LTS.
It compiles happily on Ubuntu 13.10 and Gentoo.
I tried compiling with as much staticness as I could, but it still depends on a glibc that centos doesn't have:
matiu#matiu-laptop:~/projects/cdnalizer/build/src/apache$ readelf -d mod_cdnalizer.so | grep NEED
0x0000000000000001 (NEEDED) Shared library: [libapr-1.so.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000006ffffffe (VERNEED) 0xd520
0x000000006fffffff (VERNEEDNUM) 3
build line:
/usr/bin/g++ -fPIC -I/usr/local/include -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/x86_64-linux-gnu/c++/4.8 -Wall -Wextra -g -shared -Wl,-soname,mod_cdnalizer.so -o mod_cdnalizer.so CMakeFiles/mod_cdnalizer.dir/mod_cdnalizer.cpp.o CMakeFiles/mod_cdnalizer.dir/config.cpp.o CMakeFiles/mod_cdnalizer.dir/filter.cpp.o ../libbase.a -lapr-1
I have tried compiling gcc-4.8.2 on centos, but the binaries it produces have similar glibc dependencies:
[root#matt src]# ./test_config
./test_config: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by ./test_config)
./test_config: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./test_config)
I heard that you can't escape glibc dependencies for shared libraries because c++ throws excoptions and so needs the shared libstdc++ (but my lib doesn't throw exceptions across the library boundary).
I also heard that you can't link in glibc statically because the static lib was not compiled with -fPIC.
My main question is:
How can I distribute my c++11 shared library on centos6 ?
My sub questions are:
Can I compile a c++11 shared library on ubuntu 13.10, and have it load on centos6 (and older ubuntus) ? how ?
Can I compile a c++11 shared library on centos6 and have it work on standard centos installs ?
(Don't worry about Apache2.2 vs 2.4 dependency .. that's the easy bit)
Can I compile a c++11 shared library on centos6 and have it work on standard centos installs ?
If you can't build your code with the standard CentOS 6 g++/glibc/libstdc++, then no, it's not going to run on standard CentOS 6 installs.
The CentOS distro is for long term support (LTS). Critical bugs get fixed with updates, but software otherwise doesn't change, usually. This is a feature. Even with 3rd party repositories (e.g. EPEL), the available software for CentOS isn't really recent.
Can I compile a c++11 shared library on ubuntu 13.10, and have it load on centos6 (and older ubuntus) ? how ?
If you can compile it using the g++ 4.4 toolchain, sure. In this case, you cannot use a more advanced compiler. A quick search on Ubuntu's 12.04 LTS package list shows libstdc++6-4.5-dbg using a version of libstdc++.so.6 which would be backward incompatible, based on error messages above.
How can I distribute my c++11 shared library on centos6 ?
As you've shown above, you'll have at least one updated dependency (libstdc++.so.6) that you'll need to ship with your library, and install in some odd location, with it's attendant headaches (LD_LIBRARY_PATH, what happens to any other C++ plugins, etc.). And update at some point.
Some enterprise users would object to something like this, mainly because it doesn't mesh well with the existing OS.
Statically linking in dependencies (like in Ali's answer with the Developer Toolset below) could work also. It's also not without problems (updates to dependencies again), but might be the best chance for your code to work on CentOS 6.
I see from comments to Ali's answer, that devtools 1 (gcc 4.7.0) didn't work, making it unlikely that devtools 1.1 would work. So it seems you do need C++11 support up to the level of gcc 4.8 in this case.
Your problem has nothing to do with GLIBC.
Your problem is that libstdc++.so.6 on the CentOS6 is too old.
According to distrowatch, CentOS 6.5 shipped with GCC 4.4.7. C++11 support was mostly complete in GCC 4.8, and in 4.4 had only incomplete support.
If you can build your library with GCC 4.4.7, then it should work (provided you build it on an old enough system). If you can't, then you'll have to update GCC on your target CentOS system.
Alternatively, you can distribute a newer version of libstdc++.so.6 (one from GCC 4.8), install it in non-default location, and ask your customers to link against that newer version (either via LD_LIBRARY_PATH, or better by supplying appropriate -Wl,-rpath=... option at link time).
In short:
Things are only backward compatible. You need to pick the oldest
release of the distro you want to support and build on
that. The later releases of that distro will most likely be backward
compatible so your shared library will do just fine on later releases.
You either need to build the compiler with C++11 support from source or install it from some repo of the distro. Prefer the latter if possible due to compatibility issues.
Any non-system library should be statically linked into your shared
library: -Wl,--static -lmylib1 -lmylib2 -Wl,--dynamic. The important here is that -Wl,--dynamic is at the end, after all statically linked stuff.
I haven't tried it myself but my colleague who does this routinely says:
Use CentOS 6.5 (the latest of the 6.x versions as of writing).
Install devtools / Developer Toolset. The compatibility issues are supposed to be resolved by special, patched version of the developer tools. Developer Toolset 2.1 Beta comes with gcc 4.8.
Link statically all third party libraries and libstdc++. However, do not
link glibc and other system libraries statically that are supposed to be on the target machine
anyway.
The programs that my colleague compiles this way work on my Ubuntu machine just fine. (He uses CentOS 5.10, which seems to be the oldest, still supported distro that has glibc 2.5.)
Hope this helps.