[C++] Functions optimized away in self-made library

Started by
2 comments, last by joanusdmentia 17 years, 10 months ago
Hello, I'm using MS V++ 2005 Express Edition. I've reorganized one of my projects and put some of the utility functions used by the project in a separate project (but as part of the same solution) and added the library project as a dependency to my actual application project, so the compiler knows that it's supposed to link my application against the library file created in the utility project. This works to some degree. The library project builds with 0 errors, 0 warnings. However, for some utility functions which do not get called in the library itself but are referenced by my application, the linker spits out error LNK2019: unresolved external symbol bla bla bla". I'm thinking that when compiling my utility library, the compiler notices that these functions aren't actually used anyway and just optimizes them away. Does anyone know how I can stop it from doing that? Any help appreciated!
Advertisement
First, if you're building a .lib file I'll guarenttee that they're not being optimized out because they're not used. This only happens in the link stage, and since no linking occurs when creating a .lib it can't happen. If you're building a DLL however, this can happen if you forget to export the functions.

Things to check for include:

* If you're using extern "C" anywhere, make sure it's being applied correctly while building both the library and the executable
* If you're mixing C and C++, make sure that you are using extern "C"
* Check that the default calling convention is the same in both projects (or if you want them different that you explicitly specify the calling convention in the library's headers)
* You're functions aren't marked static or inlined
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Aha, I see. I've never built a library of my own before (although I've used third-party libraries before) so sorry if I was talking bull.

Anyway, I have no 'extern's of any sort in my solution at all, and everything is in C++. One of the functions is inline tho. Well, I'm just going to remove the inline modifier from that function.

Wait, I've just made the inline function non-inline but it's still not working. Oh boy, I'm in deep doodoo. :( Can anyone point me to a good library making tutorial / FAQ? I think I need to do some reading.
Could you post the function declaration? Is it in a .cpp or .h file? I'm assuming you're just making a .lib library and not a DLL.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement