I have a libstdc++_pic.a on my system (Ubuntu 12.04, gcc 4.6.3), presumably this is the version of libstdc++ created with -fPIC. I also have a libstdc++.a.
I see the following error when I try to statically link libstdc++ with a shared library via the -static-libstdc++ link flag:
:-1: error: /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a(functexcept.o): relocation R_X86_64_32 against `std::bad_exception::~bad_exception()' can not be used when making a shared object; recompile with -fPIC
So I'm assuming it is using the non pic version, as I would expect based on the default naming. How can I instruct the linker to use the libstdc++_pic.a file?
Update 1
The _pic version is in the 32 bit gcc subfolder at /usr/lib/gcc/x86_64-linux-gnu/4.6/32, and I don't see a _pic version in the parent folder where the 64 bit versions are located. It appears that my version of gcc was not compiled with a 64 bit PIC static libstdc++.a.
Update 2
I was able to install the 64 bit version of libstdc++_pic.a by checking my gcc version and then installing the package:
gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
sudo apt-get install libstdc++6-4.6-pic
And now I see it in /usr/lib/gcc/x86_64-linux-gnu/4.6/. Still need to figure out how to tell linker to use it.
I seem to have fixed this by passing the -nostdlib linker option, and then explicitly linking libstdc++_pic.
However, now I am getting the following error:
version node not found for symbol std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_M_move(wchar_t*, wchar_t const*, unsigned long)##GLIBCXX_3.4.5
After researching it appears there may have been a bug for static libstdc++ 64bit with pic, which is now addressed in newer versions of gcc (4.7.3). This other question has more information:
Compiling one shared library on Linux to target all distributions
Related
When using clang v8.0.0 on Windows (from llvm prebuilt binaries) with -g or -gline-tables-only source map tables are not being picked up by gdb or lldb debuggers.
Upon including -g flag file grows in size (which is to be expected) yet neither gdb nor lldb pickes the source up
When compiled with gcc though (with -g flag) source files are detected by debugger.
I have tried running the same command (clang -g <codefile>) on macOS High Sierra (clang -v says it is Apple LLVM version 10.0.0 (clang-1000/10.44.4)) where there source files are being picked up by lldb. So I guessed it is localized to my windows instance or llvm for windows build.
P.S. output of clang -v on windows:
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
On Windows, Clang is not self-sufficient (at least not the official binaries). You need to have either GCC or MSVC installed for it to function.
As Target: x86_64-pc-windows-msvc indicates, by default your Clang is operating in some kind of MSVC-compatible mode. From what I gathered, it means using the standard library and other libraries provided by your MSVC installation, and presumably generating debug info in some MSVC-specific format.
Add --target=x86_64-w64-windows-gnu to build in GCC-compatible mode. (If you're building for 32 bits rather than 64, replace x86_64 with i686). This will make Clang use headers & libraries provided by your GCC installation, and debug info should be generated in a GCC-compatible way. I'm able to debug resulting binaries with MSYS2's GDB (and that's also where my GCC installation comes from).
If you only have GCC installed and not MSVC, you still must use this flag.
How do I know this is the right --target? This is what MSYS2's Clang uses, and I assume they know what they're doing. If you don't want to type this flag every time, you can replace the official Clang with MSYS2's one, but I'm not sure if it's the best idea.
(I think they used to provide some patches to increase compatibility with MinGW, but now the official binaries work equally well, except for the need to specify the target. Also, last time I checked their binary distribution was several GB larger, due to their inability to get dynamic linking to work. Also some of the versions they provided were prone to crashing. All those problems come from them building their Clang with MinGW, which Clang doesn't seem to support very well out of the box. In their defence, they're actively maintaining their distribution, and I think they even ship libc++ for Windows, which the official distribution doesn't do.)
I am running gcc version 9.4 on MacOS Monterey. I am compiling a simple program with asan enabled. Whenever I do compile, I compile successfully, but I get the following warnings:
ld: warning: dylib (/usr/local/Cellar/gcc#9/9.4.0/lib/gcc/9/libasan.dylib) was built for newer macOS version (11.3) than being linked (11.2)
ld: warning: dylib (/usr/local/Cellar/gcc#9/9.4.0/lib/gcc/9/libubsan.dylib) was built for newer macOS version (11.3) than being linked (11.2)
I do not want to upgrade my version of gcc because my remote machine uses gcc 9.4 and I do not have sudo access on that machine to upgrade it.
I have tried using the -L flag along with the following directory:
-L/usr/local/Cellar/gcc#9/9.4.0/lib/gcc/9/, but that also did not get rid of the warning. Is there a way I can fix this warning while also not upgrading my version of gcc?
Edit: gcc was installed via Homebrew
I have a virtual machine with ArchLinux installed. Here when I compile with GCC by running gcc file.c it gives me a shared library instead of an executable.
Later I find out that the problem is related only to GCC 7.2, in fact, when I compile with GCC 6.4, the output file is an executable.
How do I fix this?
The file utility is just incorrect in calling your program a shared library. It is a position-independent executable (PIE). If you really don't want this, you can specify -no-pie at link time, or build a gcc toolchain with --disable-default-pie, but in general you shouldn't need to change this.
To complement the answer that mentioned file as you pointed out in the comments, the default a.out generated by GCC is not a shared library but instead interpreted as a shared object by file maybe because of the content of your source code. Check this for more information.
When I am trying to compile a package on arm64, It gives me the error
hidden symbol 'pthread_atfork' in /usr/lib/aarch64-linux-gnu/libpthread_nonshared.a (pthread_atfokr.oS) is referenced by DSO. fatal link failed:Bad value.
gcc version 4.8.2 (Ubuntu/Linaro 4.8.2-19ubuntu1)
I tried replacing -lpthread with -pthread in make file which of no use. I also tried to cross-compile the package and then run on arm which even resulted in the same error.I have been searching for a solution couldnot find any. The package works well with linux-x86. …
Let me know if you need any more information.
Thanks in advance.
extracting pthread_atfork.o form libpthread.a and including the file pthrea_atfork.o in makefile made s2n work on ARM.
On my Linux platform, I have several versions of gcc.
Under usr/bin I have:
gcc34
gcc44
gcc
Here are some outputs:
$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
$ gcc44 --version
gcc44 (GCC) 4.4.0 20090514 (Red Hat 4.4.0-6)
I need to use the 4.4 version of gcc however the default seems to the 4.1 one.
I there a way to replace /usr/bin/gcc and make gcc44 the default compiler not using a symlink to /usr/bin/gcc44 ?
The reason why I can't use a symlink is because my code will have to be shipped in a RPM package using mock. mock creates a minimal linux installation from scratch and just install the specified dependencies before compiling my code in it. I cannot customize this "minimal installation".
Ideally, the perfect solution would be to install an official RPM package that replaces gcc with gcc44 as the default compiler. Is there such a package ? Is this even possible/good ?
Additional information
I have to use SCons (a make alternative) and it doesn't let me specify the binary to use for gcc.
I will also accept any answer that will tell me how to specify the gcc binary in my SConstruct file.
One way is to compile and install gcc from source.
See http://old.nabble.com/Choosing-compiler-td4675207.html
From that:
env = Environment()
env.Replace(CC = "my_cc_compiler")
Or, as per the answer to this question,
env['CC'] = 'gcc44'
This is a long way in the past now, but I just thought I'd add the solution I found, which doesn't require changing the SConscript file. It was useful for me as I need to build v8 under centos 5, so possibly it may be useful for someone else too.
CC=gcc44 CXX=g++44 scons
That's it!