c++ - Why can I link two libraries exporting the same C-Function in VC? -
i have situation 2 c++ libraries export same c-function symbols shared code. when compile executable links both libraries, not linker error or warning vc12. why this? silently chooses 1 of 2 symbols , have no idea 1 chosen.;
extern "c" { __declspec(dllexport) int function(void* argument);}
there flag named /force whould able convice vc compile if there multiply defined symbols, flag not set.
i not find official information microsoft why links @ all. expecting lnk4006 warning, don't.
- i want know if expected or undefined behavior, did not explode coincidence. read things 1 definition rule not being applied c-code, cannot find reliable statement vc compiler.
- can assume that, given functions not use singletons, use same code , compiler flags, not matter 1 chosen?
you violating one definition rule. behavior of program undefined.
see section "3.2 1 definition rule [basic.def.odr]" in c++ standard.
- every program shall contain exactly 1 definition of every non-inline function or variable odr-used in program; no diagnostic required. ...
section 3.2.6 describes when there can more 1 definition of class type, inline function external linkage etc. in program.
- i want know if expected or undefined behavior, did not explode coincidence. read things 1 definition rule not being applied c-code, cannot find reliable statement vc compiler.
- it undefined behavior.
- the c++ standard master, not vc compiler.
- can assume that, given functions not use singletons, use same code , compiler flags, not matter 1 chosen?
- it still undefined behavior - though program might appear behave expected.
Comments
Post a Comment