Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable error when linking if a function is not implemented

Tags:

c++

g++

linker

I noticed that when linking a project using G++, if there are functions that are declared, but not implemented, there are no errors, unless I try to call them.

Q1: Is it possible to enable an error (or at least warning) if a function is declared but not implemented?

Q2: Why this behavior?

(Note: I am using G++ 4.7.0, ld 2.22 if that is the linker used by gcc, from the mingw package)

like image 636
Tibi Avatar asked Jan 28 '26 23:01

Tibi


1 Answers

A2: An entity such as a non-inline function with external linkage can have zero or one definitions in a program. It is only required to have one definition if it is actually used (strictly odr-used) - e.g. by being called. g++ would be in error if it issued an error for an undefined function that wasn't used.

A1: So it is not possible (in a conforming way) to force this to be an error.

like image 123
CB Bailey Avatar answered Jan 30 '26 17:01

CB Bailey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!