[C++] Functions optimized away in self-made library
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!
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
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement