How to prevent the Visual C++ linker from including every function whose address is taken? -


the question pretty simple. let's compile & link code:

static char const *foo() { static char const *baz = "0123456789abcdef"; return baz; } static char const *(*bar)() = foo; int main() { return 0; } 

the visual c++ compiler or linker automatically seems mark string baz used, , includes it, though never used (despite fact foo's address taken).

is there way make compiler or linker avoid including code isn't used?

separating foo() , bar() different obj file (i.e., different cpp) start - not enough. turns out when linking executable linker pulls in every obj file built exe anyway.

the second part of solution extract cpp foo() , bar() static library, , have executable main() link against it.

afaict exact vc linking apparatus isn't officially documented, surveyed raymond here. also, not work if check 'use library dependency inputs'


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -