* Linking problems when passing linker flags before files
@ 2021-04-20 19:41 Jakub Nowak
2021-04-20 19:48 ` Tadeus Prastowo
2021-04-20 20:52 ` Jonathan Wakely
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Nowak @ 2021-04-20 19:41 UTC (permalink / raw)
To: gcc-help
Hello,
when I compile my program like this `g++ -std=c++17 -lstdc++fs test.cpp -o
test` it fails to compile because of linker errors. The reasons is that
`test.cpp` should some before `-lstdc++fs`.
This is a serious problem because it's very hard to debug it.
I'm wondering, why is this required to have files before linker flags and
if I should report this as a bug.
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Linking problems when passing linker flags before files
2021-04-20 19:41 Linking problems when passing linker flags before files Jakub Nowak
@ 2021-04-20 19:48 ` Tadeus Prastowo
2021-04-20 20:52 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Tadeus Prastowo @ 2021-04-20 19:48 UTC (permalink / raw)
To: Jakub Nowak; +Cc: gcc-help
Hello,
On Tue, Apr 20, 2021 at 9:42 PM Jakub Nowak <j.nowak26@student.uw.edu.pl> wrote:
>
> Hello,
>
> when I compile my program like this `g++ -std=c++17 -lstdc++fs test.cpp -o
> test` it fails to compile because of linker errors. The reasons is that
> `test.cpp` should some before `-lstdc++fs`.
You mean to write "should come before".
> This is a serious problem because it's very hard to debug it.
> I'm wondering, why is this required to have files before linker flags and
> if I should report this as a bug.
No, it is not a bug.
The reason why the ordering is like that is because the linker needs
to know what symbols are missing before the linker can resolve them.
So, if the library comes before the program that needs the library,
the linker will issue an error because the symbols found in the
program cannot be resolved. Yes, the linker has seen the library
before, but, to save memory, the linker does not remember what it sees
in the library. To save memory, the linker only remembers what
symbols need to be resolved and forgets the symbols as soon as they
are resolved.
> Jakub
--
Best regards,
Tadeus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Linking problems when passing linker flags before files
2021-04-20 19:41 Linking problems when passing linker flags before files Jakub Nowak
2021-04-20 19:48 ` Tadeus Prastowo
@ 2021-04-20 20:52 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2021-04-20 20:52 UTC (permalink / raw)
To: Jakub Nowak; +Cc: gcc-help
On Tue, 20 Apr 2021 at 21:42, Jakub Nowak wrote:
>
> Hello,
>
> when I compile my program like this `g++ -std=c++17 -lstdc++fs test.cpp -o
> test` it fails to compile because of linker errors. The reasons is that
> `test.cpp` should some before `-lstdc++fs`.
This is a FAQ: http://c-faq.com/lib/libsearch.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-20 20:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 19:41 Linking problems when passing linker flags before files Jakub Nowak
2021-04-20 19:48 ` Tadeus Prastowo
2021-04-20 20:52 ` Jonathan Wakely
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).