# extending kdb with c/c++ on msvc 2010

**URL:** https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [February 25, 2011, 10:30pm UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033 "2011-02-25T22:30:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)
#### Post date: [February 25, 2011, 10:30pm UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/1 "2011-02-25T22:30:00Z")

</div>

Hi all,does anybody succesfully compile a c++ dll to be used in kdb?I succesfully compile the following code on msvc 2010 as a dll.But the functions are not recognized by kdb. Please see the followingcode:# include \<k.h\>\_\_declspec(dllexport) K\_\_cdecl foo(K x){return x;}A dll called ex4.dll is created.Using the following staement in kdbfoo: `ex4 2:(`foo;1);should load this dll in kdb. But kdb reported that the procedure foois not found in the module ex4.Can anybody help?Am i missing something ?? Do i need to add some compiler specificparameters ?The compiler from msvc cannot be used ???Thanks for any help or hint.Regards,Kim\</k.h\>

---

<div class="post-metadata">

### Author: ![Kamil\_Jaskiewic](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@Kamil\_Jaskiewic](https://forum.kx.com/u/Kamil_Jaskiewic)
#### Post date: [February 26, 2011, 8:30am UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/2 "2011-02-26T08:30:00Z")

</div>

Looks like you are missing module definition file in VS. Add file  
named ex4.def with the following contents:

LIBRARY “ex4”

EXPORTS  
foo

And add it in project properties (Linker-\>Input-\>Module Definition  
File = ex4.def). If it still doesn’t work then check it with  
Dependency Walker (you might be missing some required dll’s on your  
PATH).

Regards,  
Kamil

---

<div class="post-metadata">

### Author: ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)
#### Post date: [February 26, 2011, 10:19am UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/3 "2011-02-26T10:19:00Z")

</div>

Hi Kamil,thanks for your reply.On 26 Feb., 09:30, Kamil Ja?kiewicz \<jaskiewicz.ka…\>wrote:\> Looks like you are missing module definition file in VS. Add file\> named ex4.def with the following contents:\>\> LIBRARY “ex4”\>\> EXPORTS\> ? ? foo\>\> And add it in project properties (Linker-\>Input-\>Module Definition\> File = ex4.def).In newer compiler versions, you can export data, functions, classes,or class member functions from a DLL using the \_\_declspec(dllexport)keyword.So that’s why i didnt define a \*.def file.\> If it still doesn’t work then check it with\> Dependency Walker (you might be missing some required dll’s on your\> PATH).I checked the dependy with Walker. And Walker really recognize thefunction foo. See the output from Walkerstruct k0 \* foo(struct k0 \*)It also shows dependency on others dlls:EX4.DLLKERNEL32.DLLMSVCR100.DLLNTDLL.DLLThese are also needed from kdb???I will try to load it from kdb also.Regards,Kim\>\> Regards,\> Kamil\>\> On 25 February 2011 23:30, kuentang \<kuent…\> wrote:\>\> \> Hi all,\>\> \> does anybody succesfully compile a c++ dll to be used in kdb?\>\> \> I succesfully compile the following code on msvc 2010 as a dll.\> \> But the functions are not recognized by kdb. Please see the following\> \> code:\>\> \> # include \<k.h\>\> \>\_\_declspec(dllexport) K \_\_cdecl foo(K x){return x;}\>\> \> A dll called ex4.dll is created.\>\> \> Using the following staement in kdb\>\> \> foo: `ex4 2:(`foo;1);\>\> \> should load this dll in kdb. But kdb reported that the procedure foo\> \> is not found in the module ex4.\> \> Can anybody help?\>\> \> Am i missing something ?? Do i need to add some compiler specific\> \> parameters ?\> \> The compiler from msvc cannot be used ???\>\> \> Thanks for any help or hint.\>\> \> Regards,\>\> \> Kim\>\> \> –\> \>

Submitted via Google Groups\</k.h\>\</kuent…\>\</jaskiewicz.ka…\>

---

<div class="post-metadata">

### Author: ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)
#### Post date: [February 26, 2011, 10:57am UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/4 "2011-02-26T10:57:00Z")

</div>

Hi Kamil,i followed your tips using the def file. And it works. Thx for yourhelp again.The conclusion is that the keyword \_\_declspec(dllexport) frommicrodoof is not relyable.Cheers,KimOn 26 Feb., 09:30, Kamil Ja?kiewicz \<jaskiewicz.ka…\>wrote:\> Looks like you are missing module definition file in VS. Add file\> named ex4.def with the following contents:\>\> LIBRARY “ex4”\>\> EXPORTS\> ? ? foo\>\> And add it in project properties (Linker-\>Input-\>Module Definition\> File = ex4.def). If it still doesn’t work then check it with\> Dependency Walker (you might be missing some required dll’s on your\> PATH).\>\> Regards,\> Kamil\>\> On 25 February 2011 23:30, kuentang \<kuent…\> wrote:\>\> \> Hi all,\>\> \> does anybody succesfully compile a c++ dll to be used in kdb?\>\> \> I succesfully compile the following code on msvc 2010 as a dll.\> \> But the functions are not recognized by kdb. Please see the following\> \> code:\>\> \> # include \<k.h\>\> \> \_\_declspec(dllexport) K\_\_cdecl foo(K x){return x;}\>\> \> A dll called ex4.dll is created.\>\> \> Using the following staement in kdb\>\> \> foo: `ex4 2:(`foo;1);\>\> \> should load this dll in kdb. But kdb reported that the procedure foo\> \> is not found in the module ex4.\> \> Can anybody help?\>\> \> Am i missing something ?? Do i need to add some compiler specific\> \> parameters ?\> \> The compiler from msvc cannot be used ???\>\> \> Thanks for any help or hint.\>\> \> Regards,\>\> \> Kim\>\> \> –\> \>

Submitted via Google Groups\</k.h\>\</kuent…\>\</jaskiewicz.ka…\>

---

<div class="post-metadata">

### Author: ![Kamil\_Jaskiewic](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@Kamil\_Jaskiewic](https://forum.kx.com/u/Kamil_Jaskiewic)
#### Post date: [February 26, 2011, 10:58am UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/5 "2011-02-26T10:58:00Z")

</div>

On 26 February 2011 11:19, kuentang wrote:  
\>  
\> Hi Kamil,  
\>  
\> thanks for your reply.  
\>  
\> On 26 Feb., 09:30, Kamil Ja=C5=9Bkiewicz \<jaskiewicz.ka…\>  
\> wrote:  
\>\> Looks like you are missing module definition file in VS. Add file  
\>\> named ex4.def with the following contents:  
\>\>  
\>\> LIBRARY “ex4”  
\>\>  
\>\> EXPORTS  
\>\> =C2=A0 =C2=A0 foo  
\>\>  
\>\> And add it in project properties (Linker-\>Input-\>Module Definition  
\>\> File =3D ex4.def).  
\>  
\> In newer compiler versions, you can export data, functions, classes,  
\> or class member functions from a DLL using the \_\_declspec(dllexport)  
\> keyword.  
\> So that’s why i didnt define a \*.def file.  
\>  
\>\> If it still doesn’t work then check it with  
\>\> Dependency Walker (you might be missing some required dll’s on your  
\>\> PATH).  
\>  
\> I checked the dependy with Walker. And Walker really recognize the  
\> function =C2=A0foo. See the output from Walker  
\>  
\> struct k0 \* foo(struct k0 \*)  
\>  
\> It also shows dependency on others dlls:  
\>  
\> EX4.DLL  
\> KERNEL32.DLL  
\> MSVCR100.DLL  
\> NTDLL.DLL  
\>  
\> These are also needed from kdb???  
\>  
They are needed to be on your PATH.  
  
I’ve sent you working example.  
  
Regards,  
Kamil  
  
  
\> I will try to load it from kdb also.  
\>  
\> Regards,  
\>  
\> Kim  
\>  
\>\>  
\>\> Regards,  
\>\> Kamil  
\>\>  
\>\> On 25 February 2011 23:30, kuentang \<kuent…\> wrote:  
\>\>  
\>\> \> Hi all,  
\>\>  
\>\> \> does anybody succesfully compile a c++ dll to be used in kdb?  
\>\>  
\>\> \> I succesfully compile the following code on msvc 2010 as a dll.  
\>\> \> But the functions are not recognized by kdb. Please see the following  
\>\> \> code:  
\>\>  
\>\> \> # include \<k.h\>  
\>\> \>\_\_declspec(dllexport) K \_\_cdecl foo(K x){return x;}  
\>\>  
\>\> \> A dll called ex4.dll is created.  
\>\>  
\>\> \> Using the following staement in kdb  
\>\>  
\>\> \> foo: `ex4 2:(`foo;1);  
\>\>  
\>\> \> should load this dll in kdb. But kdb reported that the procedure foo  
\>\> \> is not found in the module ex4.  
\>\> \> Can anybody help?  
\>\>  
\>\> \> Am i missing something ?? Do i need to add some compiler specific  
\>\> \> parameters ?  
\>\> \> The compiler from msvc cannot be used ???  
\>\>  
\>\> \> Thanks for any help or hint.  
\>\>  
\>\> \> Regards,  
\>\>  
\>\> \> Kim  
\>\>  
\>\> \> –  
\>\> \> You received this message because you are subscribed to the Google Gro=  
ups “Kdb+ Personal Developers” group.  
\>\> \> To post to this group, send email to personal-kdbplus@googlegroups.com=  
.  
\>\> \> To unsubscribe from this group, send email to personal-kdbplus+unsubsc=  
[ribe@googlegroups.com](mailto:ribe@googlegroups.com).  
\>\> \> For more options, visit this group athttp://groups.google.com/group/pe=  
rsonal-kdbplus?hl=3Den.  
\>  
\> –  
\>

Submitted via Google Groups\</k.h\>\</kuent…\>\</jaskiewicz.ka…\>

---

<div class="post-metadata">

### Author: ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)
#### Post date: [February 27, 2011, 7:31pm UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/6 "2011-02-27T19:31:00Z")

</div>

Hi Kamil,i tested your demo project. And it works out of the box. Thanksagain.On the other hand what i ’ ve seen from other sources are that usingthe keyword \_\_declspec(dllexport) should be enoughto export thefunctions.Do you have a working demo project where the def file is not needed ?Regards,KimOn 26 Feb., 11:58, Kamil Ja?kiewicz \<jaskiewicz.ka…\>wrote:\> On 26 February 2011 11:19, kuentang \<kuent…\> wrote:\>\>\>\> \> Hi Kamil,\>\> \> thanks for your reply.\>\> \> On 26 Feb., 09:30, Kamil Ja?kiewicz \<jaskiewicz.ka…\>\> \> wrote:\> \>\> Looks like you are missing module definition file in VS. Add file\> \>\> named ex4.def with the following contents:\>\> \>\> LIBRARY “ex4”\>\> \>\> EXPORTS\> \>\> ? ? foo\>\> \>\> And add it in project properties (Linker-\>Input-\>Module Definition\> \>\> File = ex4.def).\>\> \> In newer compiler versions, you can export data, functions, classes,\> \> or class member functions from a DLL using the \_\_declspec(dllexport)\> \> keyword.\> \> So that’s why i didnt define a \*.def file.\>\> \>\> If it still doesn’t work then check it with\> \>\> Dependency Walker (you might be missing some required dll’s on your\> \>\> PATH).\>\> \> I checked the dependy with Walker. And Walker really recognize the\> \> function ?foo. See the output from Walker\>\> \> struct k0 \* foo(struct k0 \*)\>\> \> It also shows dependency on others dlls:\>\> \> EX4.DLL\> \> KERNEL32.DLL\> \> MSVCR100.DLL\> \> NTDLL.DLL\>\> \> These are also needed from kdb???\>\> They are needed to be on your PATH.\>\> I’ve sent you working example.\>\> Regards,\> Kamil\>\> \> I will try to load it from kdb also.\>\> \> Regards,\>\> \> Kim\>\> \>\> Regards,\> \>\> Kamil\>\> \>\> On 25 February 2011 23:30, kuentang \<kuent…\> wrote:\>\> \>\> \> Hi all,\>\> \>\> \> does anybody succesfully compile a c++ dll to be used in kdb?\>\> \>\> \> I succesfully compile the following code on msvc 2010 as a dll.\> \>\> \> But the functions are not recognized by kdb. Please see the following\> \>\> \> code:\>\> \>\> \> # include \<k.h\>\> \>\> \>\_\_declspec(dllexport) K \_\_cdecl foo(K x){return x;}\>\> \>\> \> A dll called ex4.dll is created.\>\> \>\> \> Using the following staement in kdb\>\> \>\> \> foo: `ex4 2:(`foo;1);\>\> \>\> \> should load this dll in kdb. But kdb reported that the procedure foo\> \>\> \> is not found in the module ex4.\> \>\> \> Can anybody help?\>\> \>\> \> Am i missing something ?? Do i need to add some compiler specific\> \>\> \> parameters ?\> \>\> \> The compiler from msvc cannot be used ???\>\> \>\> \> Thanks for any help or hint.\>\> \>\> \> Regards,\>\> \>\> \> Kim\>\> \>\> \> –\> \>\> \>

Submitted via Google Groups\</k.h\>\</kuent…\>\</jaskiewicz.ka…\>\</kuent…\>\</jaskiewicz.ka…\>

---

<div class="post-metadata">

### Author: ![Kamil\_Jaskiewic](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@Kamil\_Jaskiewic](https://forum.kx.com/u/Kamil_Jaskiewic)
#### Post date: [February 27, 2011, 7:50pm UTC](https://forum.kx.com/t/extending-kdb-with-c-c-on-msvc-2010/7033/7 "2011-02-27T19:50:00Z")

</div>

On 27 February 2011 20:31, kuentang wrote:  
\>  
\> Hi Kamil,  
\>  
\> i tested your demo project. And it works out of the box. Thanks  
\> again.  
\>  
\> On the other hand what i ’ ve seen from other sources are that using  
\> the keyword \_\_declspec(dllexport) should be enoughto export the  
\> functions.  
\> Do you have a working demo project where the def file is not needed ?  
I always used DEF files in VS projects. But quick google says that you  
don’t have use it. But then the function name has a leading underscore  
(\_):  
[http://stackoverflow.com/questions/3314941/export-function-from-a-dll-use-d=](http://stackoverflow.com/questions/3314941/export-function-from-a-dll-use-d=)  
ef-file-or-dllexport  
[http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/cb45d1ba-5f7c-=](http://social.msdn.microsoft.com/Forums/en/vclanguage/thread/cb45d1ba-5f7c-=)  
4e34-9d63-2b7991eb50ed  
  
Regards,  
Kamil  
  
\>  
\> Regards,  
\>  
\> Kim  
\>  
\>  
\> On 26 Feb., 11:58, Kamil Ja=C5=9Bkiewicz \<jaskiewicz.ka…\>  
\> wrote:  
\>\> On 26 February 2011 11:19, kuentang \<kuent…\> wrote:  
\>\>  
\>\>  
\>\>  
\>\> \> Hi Kamil,  
\>\>  
\>\> \> thanks for your reply.  
\>\>  
\>\> \> On 26 Feb., 09:30, Kamil Ja=C5=9Bkiewicz \<jaskiewicz.ka…\>  
\>\> \> wrote:  
\>\> \>\> Looks like you are missing module definition file in VS. Add file  
\>\> \>\> named ex4.def with the following contents:  
\>\>  
\>\> \>\> LIBRARY “ex4”  
\>\>  
\>\> \>\> EXPORTS  
\>\> \>\> =C2=A0 =C2=A0 foo  
\>\>  
\>\> \>\> And add it in project properties (Linker-\>Input-\>Module Definition  
\>\> \>\> File =3D ex4.def).  
\>\>  
\>\> \> In newer compiler versions, you can export data, functions, classes,  
\>\> \> or class member functions from a DLL using the\_\_declspec(dllexport)  
\>\> \> keyword.  
\>\> \> So that’s why i didnt define a \*.def file.  
\>\>  
\>\> \>\> If it still doesn’t work then check it with  
\>\> \>\> Dependency Walker (you might be missing some required dll’s on your  
\>\> \>\> PATH).  
\>\>  
\>\> \> I checked the dependy with Walker. And Walker really recognize the  
\>\> \> function =C2=A0foo. See the output from Walker  
\>\>  
\>\> \> struct k0 \* foo(struct k0 \*)  
\>\>  
\>\> \> It also shows dependency on others dlls:  
\>\>  
\>\> \> EX4.DLL  
\>\> \> KERNEL32.DLL  
\>\> \> MSVCR100.DLL  
\>\> \> NTDLL.DLL  
\>\>  
\>\> \> These are also needed from kdb???  
\>\>  
\>\> They are needed to be on your PATH.  
\>\>  
\>\> I’ve sent you working example.  
\>\>  
\>\> Regards,  
\>\> Kamil  
\>\>  
\>\> \> I will try to load it from kdb also.  
\>\>  
\>\> \> Regards,  
\>\>  
\>\> \> Kim  
\>\>  
\>\> \>\> Regards,  
\>\> \>\> Kamil  
\>\>  
\>\> \>\> On 25 February 2011 23:30, kuentang \<kuent…\> wrote:  
\>\>  
\>\> \>\> \> Hi all,  
\>\>  
\>\> \>\> \> does anybody succesfully compile a c++ dll to be used in kdb?  
\>\>  
\>\> \>\> \> I succesfully compile the following code on msvc 2010 as a dll.  
\>\> \>\> \> But the functions are not recognized by kdb. Please see the followi=  
ng  
\>\> \>\> \> code:  
\>\>  
\>\> \>\> \> # include \<k.h\>  
\>\> \>\> \> \_\_declspec(dllexport) K\_\_cdecl foo(K x){return x;}  
\>\>  
\>\> \>\> \> A dll called ex4.dll is created.  
\>\>  
\>\> \>\> \> Using the following staement in kdb  
\>\>  
\>\> \>\> \> foo: `ex4 2:(`foo;1);  
\>\>  
\>\> \>\> \> should load this dll in kdb. But kdb reported that the procedure fo=  
o  
\>\> \>\> \> is not found in the module ex4.  
\>\> \>\> \> Can anybody help?  
\>\>  
\>\> \>\> \> Am i missing something ?? Do i need to add some compiler specific  
\>\> \>\> \> parameters ?  
\>\> \>\> \> The compiler from msvc cannot be used ???  
\>\>  
\>\> \>\> \> Thanks for any help or hint.  
\>\>  
\>\> \>\> \> Regards,  
\>\>  
\>\> \>\> \> Kim  
\>\>  
\>\> \>\> \> –  
\>\> \>\> \> You received this message because you are subscribed to the Google =  
Groups “Kdb+ Personal Developers” group.  
\>\> \>\> \> To post to this group, send email to personal-kdbplus@googlegroups.=  
com.  
\>\> \>\> \> To unsubscribe from this group, send email to personal-kdbplus+unsu=  
[bscribe@googlegroups.com](mailto:bscribe@googlegroups.com).  
\>\> \>\> \> For more options, visit this group athttp://groups.google.com/group=  
/personal-kdbplus?hl=3Den.  
\>\>  
\>\> \> –  
\>\> \> You received this message because you are subscribed to the Google Gro=  
ups “Kdb+ Personal Developers” group.  
\>\> \> To post to this group, send email to personal-kdbplus@googlegroups.com=  
.  
\>\> \> To unsubscribe from this group, send email to personal-kdbplus+unsubsc=  
[ribe@googlegroups.com](mailto:ribe@googlegroups.com).  
\>\> \> For more options, visit this group athttp://groups.google.com/group/pe=  
rsonal-kdbplus?hl=3Den.  
\>  
\> –  
\>

Submitted via Google Groups\</k.h\>\</kuent…\>\</jaskiewicz.ka…\>\</kuent…\>\</jaskiewicz.ka…\>
