MSVC: __declspec(dllexport) does not symbols
I have a small issue when it comes to writing a DLL in MSVC (the 2010 version in particular). My program consists of the main part and a DLL. The DLL contains a function that is开发者_如何学Go
__declspec(dllexport) int test_function(void) {
return 42;
}
The file is compiled using a DLL project (not using pre-compiled headers, I have chosen a empty DLL project). Now, when I want to list the exported symbols using the dumpbin
tool, the test_function
is not listed under exports. Is there a specific setting that forces __declspec(dllexport)
to actually export symbols?
Any help is welcome. Thank you!
That should do it. If this is the whole code, check the following:
1) You are actually checking the correct dll. Look at the timestamp. Double-check the location and the name.
2) You are compiling the specified cpp (I take it your definition is in the cpp file). Just because the file is in the directory doesn't mean it gets compiled, make sure it is added to the project.
3) Make sure your function is not excluded from the compilation unit by preprocessor directives.
Also look for other symbols and try to see what differences are there between the symbols that get exported and your function.
If this fails, you should move __declspec(dllexport)
to your .h
file and the definition (without __declspec(dllexport)
) to your .cpp
. It might not be exported because the compiler might try to optimize it out by inlining it.
精彩评论