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.

  1. 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.
  2. 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.

  1. 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.


  1. 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.
  1. 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -