Linking library without a header file?

eli picture eli · Aug 7, 2012 · Viewed 9.1k times · Source

I'm attempting to link a static library in C++ using Visual Studio 2010. Trouble is, the library (and accompanying header ) have a lot of MFC objects in them. I would like to call one of the library's functions without recompiling my project to include MFC, or recompiling the library to not use MFC. This codeproject article seems to imply that this is possible if I define the function to be external in my project (using the "extern" keyword).

However, I've had no luck. No matter what I try, I get an unresolved external symbol error.

Is the article correct? And if not, is such linkage possible any other way?

Answer

Rafael Baptista picture Rafael Baptista · Aug 7, 2012

You can absolutely do this, you just have to find the exact right function prototype.

Use "dumpbin" to dump the symbol table, and look for your function.

If the function name looks normal - then define it, and link to it using "extern C". If the symbol is c++ mangled, then you will need to demangle it to find the prototype.

If the function is not in the symbol table - then it has been defined statically in the lib, and is not accessible. Then you're hosed. There is no way.