public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename)
@ 2023-04-03 11:34 frechbengel at gmx dot de
2023-04-03 12:30 ` [Bug c++/109389] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: frechbengel at gmx dot de @ 2023-04-03 11:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
Bug ID: 109389
Summary: g++ file.cpp -lgmp (option only works after filename)
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: frechbengel at gmx dot de
Target Milestone: ---
Hello,
1. »g++ --version« outputs:
g++ (Debian 10.2.1-6) 10.2.1 20210110
2. »g++ --help« says:
Usage: g++ [options] file...
3. But if I try to compile:
#include <gmp.h>
int main(){
mpz_t n;
mpz_init(n);
mpz_clear(n);
return 0;}
4. with »g++ -lgmp file.cpp« the error is:
/usr/bin/ld: /tmp/cc8lgHAc.o: in function `main':
guard_driver.cpp:(.text+0x10): undefined reference to `__gmpz_init'
/usr/bin/ld: guard_driver.cpp:(.text+0x21): undefined reference to
`__gmpz_set_ui'
/usr/bin/ld: guard_driver.cpp:(.text+0x34): undefined reference to
`operator<<(std::ostream&, __mpz_struct const*)'
/usr/bin/ld: guard_driver.cpp:(.text+0x55): undefined reference to
`__gmpz_clear'
collect2: error: ld returned 1 exit status
5. There is no error if I compile with:
»g++ file.cpp -lgmp«
6. As the --help says the options should be given BEFORE the filename it is a
feature if it works with options given after the filename, too. But I is
propably a bug that compilation only works with the option given after the
filename.
Regards and thank you for you valuable work
Bernd
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109389] g++ file.cpp -lgmp (option only works after filename)
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
@ 2023-04-03 12:30 ` redi at gcc dot gnu.org
2023-04-03 13:39 ` frechbengel at gmx dot de
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-03 12:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Firstly, this is a proeprty of your linker, which is not part of GCC. GCC just
passes the arguments to the linker in the order you give them.
Secondly, this is not a bug, it's the expected behaviour for the linker.
https://c-faq.com/lib/libsearch.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109389] g++ file.cpp -lgmp (option only works after filename)
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
2023-04-03 12:30 ` [Bug c++/109389] " redi at gcc dot gnu.org
@ 2023-04-03 13:39 ` frechbengel at gmx dot de
2023-04-03 13:40 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: frechbengel at gmx dot de @ 2023-04-03 13:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
--- Comment #2 from Bernd <frechbengel at gmx dot de> ---
@ Jonathan Wakely
Thank you for correcting me and setting the issue solved.
Sorry for the wrong report. For a long time g++ accepted the -lgmp before the
filename, clang++ still does. That's why I thought that this must a bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109389] g++ file.cpp -lgmp (option only works after filename)
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
2023-04-03 12:30 ` [Bug c++/109389] " redi at gcc dot gnu.org
2023-04-03 13:39 ` frechbengel at gmx dot de
@ 2023-04-03 13:40 ` jakub at gcc dot gnu.org
2023-04-03 13:46 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-03 13:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It accepts it, but it does something different from when it is after the
objects.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109389] g++ file.cpp -lgmp (option only works after filename)
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
` (2 preceding siblings ...)
2023-04-03 13:40 ` jakub at gcc dot gnu.org
@ 2023-04-03 13:46 ` redi at gcc dot gnu.org
2023-04-03 13:48 ` pinskia at gcc dot gnu.org
2023-04-03 13:57 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-03 13:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Clang is not a linker either. Both Clang and GCC just pass the options to the
linker.
Any difference in behaviour is a difference in the linker, not a difference
between Clang and GCC.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109389] g++ file.cpp -lgmp (option only works after filename)
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
` (3 preceding siblings ...)
2023-04-03 13:46 ` redi at gcc dot gnu.org
@ 2023-04-03 13:48 ` pinskia at gcc dot gnu.org
2023-04-03 13:57 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-03 13:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note for shared libraries it might the case the gcc you using defaults to
passing --as-needed to the linker and the clang driver does not.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/109389] g++ file.cpp -lgmp (option only works after filename)
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
` (4 preceding siblings ...)
2023-04-03 13:48 ` pinskia at gcc dot gnu.org
@ 2023-04-03 13:57 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-03 13:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109389
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note Debian (and Ubuntu) has a patch to their GCC which does cause the default
arguments to ld to include --as-needed . That is why you are seeing a
difference between gcc and clang. Note if you build GCC from source, you would
not have seen a difference here. Also note this is not a bug in GCC nor in
debian's gcc; just you misunderstanding the how linking works too.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-03 13:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03 11:34 [Bug c++/109389] New: g++ file.cpp -lgmp (option only works after filename) frechbengel at gmx dot de
2023-04-03 12:30 ` [Bug c++/109389] " redi at gcc dot gnu.org
2023-04-03 13:39 ` frechbengel at gmx dot de
2023-04-03 13:40 ` jakub at gcc dot gnu.org
2023-04-03 13:46 ` redi at gcc dot gnu.org
2023-04-03 13:48 ` pinskia at gcc dot gnu.org
2023-04-03 13:57 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).