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?
When a header file is included two times in a C program, the second one gets ignored. In actual, the #, called the include, preceding a header file ensures that it is included only once during the compilation process.
Yes, because it's still based on C. You can answer your own question: Don't use them and try to compile without them. If you can't, then the compilers still require them.
If your class declaration references types in the header, you will need to include it there. If it's only in the implementation, then you can include it in the cpp file.
You can have the libraries installed without the headers. You can't then compile code that uses the header, but you can run code that uses the shared library.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With