From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9A3593858C33; Sat, 30 Jul 2022 13:20:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A3593858C33 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106483] undefined reference to function implemented in shared library if putting main.cpp after options, but non of any error when putting before options Date: Sat, 30 Jul 2022 13:20:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status resolution Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jul 2022 13:20:56 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106483 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Jonathan Wakely --- Firstly, this is the linker doing this, not GCC. GCC just passes the argume= nts to the linker in the order you specify them. Secondly, this is the correct behaviour. Your linker is set up to default to --as-needed which means that shared libraries on the command line will only= get used if they satisfy a non-weak undefined reference from a regular object f= ile that has already been processed by the linker. If you put -ladd before main= .cpp then there are no undefined symbols yet, so the library is just ignored. https://web.archive.org/web/20210609020437/c-faq.com/lib/libsearch.html Either link with -Wl,--no-as-needed to change the linker's behaviour so that shared libraries are always used, or put the libraries in the right order.=