I use Cmake to generate VS project, based on some dll file by
if(WIN32)
MESSAGE(WINDOWS)
LINK_LIBRARIES(${***_Test_SOURCE_DIR}/../../Build/Win32/Release/***.dll)
else(WIN32)
开发者_开发百科 MESSAGE(POSIX)
LINK_LIBRARIES(${***_Test_SOURCE_DIR}/../../Build/POSIX/lib***.so)
endif(WIN32)
But when I open the generated project, build and it throw out
\***.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2B0
Is anyone has ideas?
If do not use CMake, how to add external dll(not reference to some project) file in VS project. Is there any strict steps I can follow?
Thanks
On Windows, you need to link against .lib and not against a .dll, that's stupid, but Microsoft uses the same .lib extension for static and dynamic libraries. There should be
***.lib
somewhere in${***_Test_SOURCE_DIR}/../../Build/Win32/Release/
.LINK_LIBRARIES(${***_Test_SOURCE_DIR}/../../Build/Win32/Release/***.lib)
If it is not the case, you can follow this article to build a
.lib
from a.dll
: How To Create 32-bit Import Libraries Without .OBJs or Source. Briefly (taken from Adrian Henke’s Blog), within a VS command prompt:dumpbin /exports C:\yourpath\yourlib.dll
This will print quite a bit of text to the console. However we are only interested in the functions:
ordinal hint RVA name
1 0 00017770 jcopy_block_row
2 1 00017710 jcopy_sample_rows
3 2 000176C0 jdiv_round_up
4 3 000156D0 jinit_1pass_quantizer
5 4 00016D90 jinit_2pass_quantizer
6 5 00005750 jinit_c_coef_controller
...etc
Now copy all those function names (only the names!) and paste them into a new textfile. Name the nextfile yourlib.def and put the line “EXPORTS” at its top. My yourlib.def file looks like this:
EXPORTS
jcopy_block_row
jcopy_sample_rows
jdiv_round_up
jinit_1pass_quantizer
jinit_2pass_quantizer
jinit_c_coef_controller
...
Now from that definition file, we can finally create the .lib file. We use the “lib” tool for this, so run this command in your Visual Studio Command Prompt:
lib /def:C:\mypath\mylib.def /OUT:C:\mypath\mylib.lib
精彩评论