I have a C source file that is automatically generated from some data:
#include <stdint.h>
size_t BlurKernel_size = 840;
unsigned char BlurKernel[] = {
0x06b, 0x65, 0x72, // ... etc
};
I compile it to an object file using
cl /nologo kernels_embedd.c /c /Fokernels_embedd.obj /W4 /O2 /MT
Then put it into a static library
lib /nologo /OUT:kernels_embedd.lib kernels_embedd.obj
Then I link it with my main program (which does extern const char* BlurKernel; extern const size_t BlurKernel_size;
):
link /nologo /OUT:main.dll /DLL main.obj kernels_embedd.lib /IMPLIB:main.lib
And I get the error
main.obj : error LNK2019: unresolved external symbol "char const * const BlurKernel" (?BlurKernel@@3PEBDEB) referenced in function "public: __cdecl BlendIop::BlendIop(class Node *)" (??0BlendIop@@QEAA@PEAVNode@@@Z)
main.obj : error LNK2019: unresolved external symbol "unsigned __int64 const BlurKernel_size" (?BlurKernel_size@@3_KB) referenced in function "public: __cdecl BlendIop::BlendIop(class Node *)" (??0BlendIop@@QEAA@PEAVNode@@@Z)
main.dll : fatal error LNK1120: 2 unresolved externals
However, looking at kernels_embedd.lib
with dumpbin
, the symbols are available:
> dumpbin kernels_embedd.lib /symbols
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file kernels_embedd.lib
File Type: LIBRARY
COFF SYMBOL TABLE
000 00AA766F ABS notype Static | @comp.id
001 00000000 SECT1 notype Static | .drectve
Section length 45, #relocs 0, #linenums 0, checksum 0
003 00000000 SECT2 notype Static | .debug$S
Section length CC, #relocs 0, #linenums 0, checksum 0
005 00000000 SECT3 notype Static | .data
Section length 358, #relocs 0, #linenums 0, checksum ABAE4B9B
007 00000000 SECT3 notype External | BlurKernel_size
008 00000010 SECT3 notype External | BlurKernel
String Table Size = 0x1F bytes
Summary
358 .data
CC .debug$S
45 .drectve
(I get the same output when looking at kernels_embedd.obj
with dumpbin
).
I have successfully used this method with GCC before. What am I doing wrong with MSVC?