Sign in to follow this  

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

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this