Re: Linking problems when passing linker flags before files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On Tue, Apr 20, 2021 at 9:42 PM Jakub Nowak <j.nowak26@xxxxxxxxxxxxxxxxx> 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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux