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
Related
I'm currently compiling sources using --coverage, with GCC. The generated .gcno files (and the instrumented libraries) are to be packed in a RPM and the code coverage evaluated on another, target platform.
Now, I'm having a problem getting the coverage data, because when I run the programs calling the instrumented code, I get messages telling me that I have a version mismatch. They look like:
".gcda:Version mismatch - expected A85R got B12R"
Now, I've seen this question: GCOV Version mismatch - expected 700e got 408R which says I must use the same toolchain when compiling and when executing the code.
I'm compiling using gcc 11.2.1, and gcov --version says the same thing, on the source platform.
On the target platform, gcc --version and gcov --version both give that very same version number.
The compiling and the testing is done on the same "physical" machine, but on different Docker containers. On both of them, the GCC version and gcov version are the same
I've done further testing: even on the Docker container where we compile, we cannot run the coverage, and get the same error. Or, to be more precise, when compiled using gcc 11, it will say "version mismatch". However, when compiled using gcc 8.5, it works.
The setup is that we have the GCC 11 toolset, which requires gcc 8.5 to install. By default, gcc 8.5 is enabled, and you have to use a script (provided by the gcc 11 toolset) to enable the later. That script updates different variables, like the PATH, LIBRARY_PATH, etc., to look at GCC 11 first.
However, I'm pretty sure it doesn't upgrade the libc.so library, and that it's the cause of the problem: I compiled two of our simplest libs (each of them having no dependencies whatsoever, except libc) with gcc 11, in coverage mode. Then I compiled a simple test program, without coverage, calling some functions from the two instrumented libs. I checked (with elfread -d), the program only links to these two libs (and libc).
Calling this test program while on the compilation container results in the Version mismatch error, which would lead me to conclude that our libc.so isn't compatible with gcc 11.
I wonder if there is a way to get a "native" gcc 11, instead of a "toolkit" package which has to be installed over a gcc 8.5 (my colleague in charge of creating the Docker containers tells me that for gcc 9 and above, there are only "toolkit" packages, requiring gcc 8.5 to install).
Our target architecture runs on Rocky Linux, and I think our development architecture is a Redhat, if it has any importance here.
When running the command:
clang --target=wasm32 -nostdlib -Wl, --no-entry -Wl, --export-all howold.c -o howold.wasm
I get the following errors:
clang-14: error: unsupported option '--no-entry'
clang-14: error: unsupported option '--export-all'
I installed LLVM using brew install llvm and linked it properly with brew link llvm, then ran source .zshrc.
Does macOS not support these directives or am I missing an install or command somewhere? I am new to LLVM and clang on macOS so this may be an installation problem but not entirely sure.
To pass arguments to the linker, there shouldn't be a space after -Wl,. With the extra space, you're trying to give the --no-entry option to clang itself, which isn't valid.
Try this:
clang --target=wasm32 -nostdlib -Wl,--no-entry -Wl,--export-all howold.c -o howold.wasm
I've just updated to OSX 10.14.6 (Mojave) and now, after upgrading Xcode and migrating MacPorts, even the simplest C program will not link with any gcc version. For example, linking the program
int main() {}
gives:
dcs16> gcc test.c
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
I am using gcc 6.5 in /opt/local/bin:
dcs16> gcc --version
gcc (MacPorts gcc6 6.5.0_4) 6.5.0
The Xcode version is 11.0 and I have installed the package (which was recommended for solving some compile problems that other people had):
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Any help is greatly appreciated.
Note: There is no problem linking with clang.
Note gcc search dirs are:
test> gcc -print-search-dirs
install: /opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/
programs: =/opt/local/libexec/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/libexec/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/libexec/gcc/x86_64-apple-darwin18/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/bin/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/bin/
libraries: =/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/lib/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/lib/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../
Adding "-L/usr/lib" solves the problem.
Also downgrading from Xcode 11.0 to Xcode 10.3 solves the problem! Note: I also checked Xcode 11.1 which just came out but the problem still exists with 11.1.
Note added: Another programmer informs me that upgrading to OSX 10.15 solves the problem. So this is an incompatibility between OSX 10.14 and Xcode 11.
[Added 28/12/2020] And another programmer informs me that he ran into this problem with Xcode 12.3. His solution was to downgrade to 12.2.
I'm using the Bochs emulator and for my class we're using gcc 4.2.1. I believe I've gotten Bochs running, but now I need to compile our programs which are compatible with gcc 4.2/.1.
I understand OSX uses an alias for gcc 4.2.1, but how can I use gcc specifically and not clang?
Edit: GCC 4.6.3 not 4.2.1 sorry
You can install previous version of gcc pretty easily using homebrew.
If you have homebrew installed you can get gcc 4.9 by running
brew install gcc#4.9
After it is installed gcc will still map to the clang that came with your mac. The newly installed gcc will be installed at /usr/local/bin and be called something like gcc-4.
You can find the exact executable name using
ls /usr/local/bin | grep gcc
Hopefully 4.9 is close enough to 4.6 for your purposes.
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