g++ (GCC) 4.7.2
3.7.6-201.fc18.x86_64 #1 SMP Mon Feb 4 15:54:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
Fedora release 18 (Spherical Cow)
Hello,
I am compiling and having a problem trying to link a program.
The linker error is:
/usr/bin/ld: point.o: undefined reference to symbol '_Znwj##GLIBCXX_3.4'
/usr/bin/ld: note: '_Znwj##GLIBCXX_3.4' is defined in DSO /lib/libstdc++.so.6 so try adding it to the linker command line
/lib/libstdc++.so.6: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
This object file is point.o is trying to call a function that doesn't exist in libstdc++.
When I try and check if the symbol name does exist using readelf I can't find it.
readelf --all libstdc++.so.6.0.17 | grep _Znwj##GLIBCXX_3.4
Is this because the point.o is looking for a symbol in a older libstdc++ that could have been removed in a later version?
Many thanks for any suggestions,
In my case I was using gcc not g++. It used to work in '12, but a later build on a different machine in '14 choked. The gnu compiler has indeed changed. The answer in my case was to add
-lstdc++
onto the end of the linking line, as the error messages suggest. HTH.
Related
How do I compile this code in CentOS 7 ? I am reading one book and in the book they use -static while compiling so that's how I did it and I get errors I mentioned below but when I dont use -static I get no errors and it compiles successfully.
First attempt:
main()
{
exit(0);
}
I get this error when I try to compile it.
$ gcc -static -o exit exit.c
exit.c: In function _main_:
exit.c:3:9: warning: incompatible implicit declaration of built-in function _exit_ [enabled by default]
exit(0);
^
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
Second attempt:
Then I google this error and lots of articles told me to include stdlib.h library so I did that as well and I get this error:
Code:
#include <stdlib.h>
main()
{
exit(0);
}
Now when I compile it, I get following error.
$ gcc -static -o exit exit.c
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
linux version:
$ uname -a
Linux localhost.localdomain 3.10.0-1127.13.1.el7.centos.plus.i686 #1 SMP Thu Jun 25 16:59:06 UTC 2020 i686 i686 i386 GNU/Linux
As #KamilCuk noted, this requires a different set of libraries for static linking, and on my CentOS 7 machine, this installs the proper libraries:
# yum install glibc-static
Then the compile should work as you expect.
The libraries installed by this package are:
$ rpm -q -l glibc-static
/usr/lib64/libBrokenLocale.a
/usr/lib64/libanl.a
/usr/lib64/libc.a
/usr/lib64/libc_stubs.a
/usr/lib64/libcrypt.a
/usr/lib64/libdl.a
/usr/lib64/libm.a
/usr/lib64/libnsl.a
/usr/lib64/libpthread.a
/usr/lib64/libresolv.a
/usr/lib64/librt.a
/usr/lib64/libutil.a
When trying to install the latest glibc into my machine provided I executed the "config" executable with flags: ../configure CFLAGS="-O3 -fPIC" --disable-sanity-checks it generates the makefile correctly, although I think disable-sanity-checks will give some errors.
But whenever I try to execute the generated Makefile using make, the console prints the following error:
make[3]: Leaving directory '/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/elf'
gcc -nostdlib -nostartfiles -shared -o /mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/ld.so.new \
-Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both -Wl,-z,defs \
/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/librtld.os -Wl,--version-script=/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/ld.map
\
-Wl,-soname=ld-linux-x86-64.so.2 \
-Wl,-defsym=_begin=0
/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/librtld.os: In function `process_envvars':
/mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/elf/rtld.c:2686: undefined reference to `__GI___open64_nocancel'
/usr/bin/ld: /mnt/c/Users/SCP173/Downloads/Thread/glib/glibc/glibc-build/elf/librtld.os: relocation R_X86_64_PC32 against undefined symbol `__GI___open64_nocancel' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
As I said, I tried to add the -fPIC flag but still didn't catch it. And I'm kind of new to .os, .map and other extensions such as those. Am I doing it completely wrong? Or else, how could I compile just that file using gcc instead of passing the flag to the whole make command?
Your file system is not set up correctly. By default, NTFS is case-preserving, but case-insensitive. As far as I understand it, current versions of WSL set up only part of the file system tree in case-sensitive mode. (A previous system-wide configuration is now disregarded.)
Building glibc requires a case-sensitive file system. Please also note that WSL is not a proper development environment for glibc because there are so many test failures due to bugs in the WSL kernel emulation.
After a successful configuration, build and installation of JACK v.2 from source, I am trying to compile a simple JACK client example:
pi#raspberrypi:~/jack $ gcc -o simple_client simple_client.c -l jack
However, the compiler returns the following errors:
/usr/bin/ld: /tmp/cc7341zz.o: undefined reference to symbol 'sin##GLIBC_2.4'
//lib/arm-linux-gnueabihf/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Are they probably due to the ARM processor architecture? Can you, please, suggest me some hint about how to solve them?
Source code of the simple_client.c file is available at this link. Furthermore, it has been successfully compiled and tested on macOS Sierra.
My compiler is pooched. I'm trying to compile a simple "Hello World" program in c and I get this error:
ld: warning: directory not found for option '- F/System/Library/Frameworks/'
ld: unknown option: -plugin
collect2: error: ld returned 1 exit status
Googling the error kept giving me links to help for MAC OS. My computer is running Ubuntu 16.04.
This came about from having this error before and implementing its solution or installing clang and removing usr/local/bin/as. Compiler still won't compile butthe error is now the aforementioned.
The program I'm trying to compile:
/* Hello World program */
#include<stdio.h>
int main()
{
printf("Hello World");
}
The uname -m commands brings back x86_64. Running as -version brings back:
GNU assembler (GNU Binutils for Ubuntu) 2.26.1
Copyright (C) 2015 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-linux-gnu'.
For what it was worth I was trying to compile a python program for iOS. Before trying that the compiler worked. What do I need to do to fix the compiler?
Read the error:
ld: warning: directory not found for option '- F/System/Library/Frameworks/' ld: unknown option: -plugin collect2: error:
ld returned 1 exit status ld doesn't know option -plugin.
Take a look at the command that link the objects. And also the directory maybe does not exists.
I just started to learn gcc/g++ by reading "An introduction to GCC"
In chapter 3.1 the author showed an example of linking with external libraries and header files. The main source code uses 'gdbm.h' header (installed at /opt/gdbm-1.8.3/include/ in text book) file and the library ‘libgdbm.a’ (installed at /opt/gdbm-1.8.3/lib/ in text book). The process of linking with the library and header file is as follows:
Link to example screenshot
When I tried to repeat this, I got a contradictory result. When I used method 1 (in the example fails) which only includes header file path, the program can be compiled, however, when I used method 2 (in the example succeeds), I got an error, saying that
"ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1"
(this is my full command line and error message:)
userMacBook-Pro:03 user$gcc -Wall -I/usr/local/include dbmain.c -L/usr/local/lib dbmain.c -lgdbm
duplicate symbol _main in:
/var/folders/6_/09vfzzms7dq1d73vl4mwlxmh0000gn/T/dbmain-9d15f9.o
/var/folders/6_/09vfzzms7dq1d73vl4mwlxmh0000gn/T/dbmain-907e96.o
this is my command that succeeds:
userMacBook-Pro:03 user$ gcc -Wall -I/usr/local/include dbmain.c -lgdbm
userMacBook-Pro:03 user$ ./a.out
Storing key-value pair... done.
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone explain why this happens?
I don't know which platform the author uses, I just use mac OS X.
gcc -Wall -I/usr/local/include dbmain.c -L/usr/local/lib dbmain.c -lgdbm
The file dbmain.c is present twice on your command line. For this reason the main function is present twice.