Re: [personal kdb+] Standalone C/C++ program using KDB ?

link with c.obj (w32) here
http://code.kx.com/wsvn/code/kx/kdb%2B/w32/?#a735e1cacd939f9eedb1c43577954dd1f

for the example http://code.kx.com/wsvn/code/contrib/wiki/csv.c,
compile like this:

cl -DKXVER=3 csv.c c.obj

which should give you csv.exe

This is the most frustrating part, i  followed exactly your steps with visual studio 2010, but still getting error messages.

I attached all files, would you please have a look … is it just me? why everyone’s telling this should work but just cannot compile on both my desktop and laptop.

csv.c

Microsoft (R) Incremental Linker Version 10.00.30319.01

Copyright (C) Microsoft Corporation.  All rights reserved.

/out:csv.exe 

csv.obj 

c.obj 

MSVCRT.lib(MSVCR100.dll) : error LNK2005: _realloc already defined in LIBCMT.lib(realloc.obj)

MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj)

MSVCRT.lib(MSVCR100.dll) : error LNK2005: __errno already defined in LIBCMT.lib(dosmap.obj)

LINK : warning LNK4098: defaultlib ‘MSVCRT’ conflicts with use of other libs; use /NODEFAULTLIB:library

c.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function _cls

c.obj : error LNK2019: unresolved external symbol __imp__ioctlsocket@12 referenced in function _snb

c.obj : error LNK2019: unresolved external symbol __imp__WSAStartup@8 referenced in function _wsa

c.obj : error LNK2019: unresolved external symbol __imp__gethostbyaddr@12 referenced in function _hl

c.obj : error LNK2019: unresolved external symbol __imp__htonl@4 referenced in function _hl

c.obj : error LNK2019: unresolved external symbol __imp__ntohl@4 referenced in function _addr

c.obj : error LNK2019: unresolved external symbol __imp__gethostbyname@4 referenced in function _addr

c.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function _addr

c.obj : error LNK2019: unresolved external symbol __imp__accept@12 referenced in function _accp

c.obj : error LNK2019: unresolved external symbol __imp__bind@12 referenced in function _cb

c.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function _cb

c.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function _cb

c.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function _cb

c.obj : error LNK2019: unresolved external symbol __imp__setsockopt@20 referenced in function _sopt

c.obj : error LNK2019: unresolved external symbol __imp__listen@8 referenced in function _lstn

c.obj : error LNK2019: unresolved external symbol __imp__ntohs@4 referenced in function _pod

c.obj : error LNK2019: unresolved external symbol __imp__getsockname@12 referenced in function _pod

c.obj : error LNK2019: unresolved external symbol __imp__getsockopt@20 referenced in function _apu

c.obj : error LNK2019: unresolved external symbol __imp__select@20 referenced in function _apu

c.obj : error LNK2019: unresolved external symbol __imp__recv@16 referenced in function _rcv

c.obj : error LNK2019: unresolved external symbol __imp__send@16 referenced in function _snd

csv.exe : fatal error LNK1120: 21 unresolved externals

Never Mind, I figured out what’s going wrong.

I am missing a library file ws2_32.lib. Passing this file to the linker solves the problem.

Best

Hi,
  I am new to this and trying to run the sample file you provided using visual studio. I got the following messages:

  error LNK2019: unresolved external symbol _khpu referenced in function _main

  I am not an expert on Visual Studio C++. It seems that I missed some settings. Can someone help? Thank you. 

Qi

you need to link with the kdb+ c-api library.
For windows 32bit -

http://kx.com/q/w32/c.lib which uses http://kx.com/q/w32/c.dll at run time

or

http://kx.com/q/w32/c.obj which does not depend on c.dll

For win 64bit, use files from http://kx.com/q/w64

Thank you. That works now!

?

Another quick question:

?

When I try to call

?

k(handle, queryString, (K)0),

?

this queryString is in type S which is defined by KDB.

?

How can I transfer a std::string to type S? I tried different ways and failed.

?

?

Qi

S is just typedef char*S,<o:p></o:p>

<o:p> </o:p>

A quick and dirty solution is just to cast the const away using <o:p></o:p>

<o:p> </o:p>

const_cast<char*>(Text.c_str())<o:p></o:p>

<o:p> </o:p>

I don’t like this solution also. So I redefine the function k(handle, queryString, (K)0), using <o:p></o:p>

typedef const char* SS;<o:p></o:p>

extern k(I,const SS,…),<o:p></o:p>

<o:p> </o:p>

HTH,<o:p></o:p>

<o:p> </o:p>

Kim<o:p></o:p>

<o:p> </o:p>

Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Qi Li
Gesendet: Donnerstag, 7. November 2013 20:42
An: personal-kdbplus@googlegroups.com
Betreff: Re: [personal kdb+] Standalone C/C++ program using KDB ?<o:p></o:p>

<o:p> </o:p>

Thank you. That works now!<o:p></o:p>

 <o:p></o:p>

Another quick question:<o:p></o:p>

 <o:p></o:p>

When I try to call <o:p></o:p>

 <o:p></o:p>

k(handle, queryString, (K)0), <o:p></o:p>

 <o:p></o:p>

this queryString is in type S which is defined by KDB. <o:p></o:p>

 <o:p></o:p>

How can I transfer a std::string to type S? I tried different ways and failed. <o:p></o:p>

 <o:p></o:p>

 <o:p></o:p>

Qi

<o:p></o:p>

On Thu, Nov 7, 2013 at 8:55 AM, Charles Skelton <charlie@kx.com> wrote:<o:p></o:p>

you need to link with the kdb+ c-api library.<o:p></o:p>

For windows 32bit -<o:p></o:p>

http://kx.com/q/w32/c.lib which uses http://kx.com/q/w32/c.dll at run time<o:p></o:p>

or<o:p></o:p>

http://kx.com/q/w32/c.obj which does not depend on c.dll<o:p></o:p>

<o:p> </o:p>

For win 64bit, use files from http://kx.com/q/w64<o:p></o:p>

<o:p> </o:p>

On Thu, Nov 7, 2013 at 2:41 PM, Qi Li <qi.li22@gmail.com> wrote:<o:p></o:p>

Hi,<o:p></o:p>

  I am new to this and trying to run the sample file you provided using visual studio. I got the following messages:<o:p></o:p>

<o:p> </o:p>

  error LNK2019: unresolved external symbol _khpu referenced in function _main<o:p></o:p>

<o:p> </o:p>

  I am not an expert on Visual Studio C++. It seems that I missed some settings. Can someone help? Thank you. <o:p></o:p>

<o:p> </o:p>

Qi<o:p></o:p>

Kim:

? Thank you very much. That works well.

?

? Regards,

?

Qi

I am new to c.dll and encounter this error if my code uses the function “K ktj(I, J)”:

error LNK2019: unresolved external symbol _ktj

Did I miss anything?

? 2013?11?7??? UTC+8??9:55:08?Charles Skelton???

you need to link with the kdb+ c-api library.
For windows 32bit -

http://kx.com/q/w32/c.lib which uses http://kx.com/q/w32/c.dll at run time

or

http://kx.com/q/w32/c.obj which does not depend on c.dll

For win 64bit, use files from http://kx.com/q/w64

> error LNK2019: unresolved external symbol _ktj

are you linking with c.lib or c.o?

> ? 2013?11?7??? UTC+8??9:55:08?Charles Skelton???
>>
>> you need to link with the kdb+ c-api library.
>> For windows 32bit -
>> http://kx.com/q/w32/c.lib which uses http://kx.com/q/w32/c.dll at run time
>> or
>> http://kx.com/q/w32/c.obj which does not depend on c.dll
>>
>> For win 64bit, use files from http://kx.com/q/w64
>>
>>
>> On Thu, Nov 7, 2013 at 2:41 PM, Qi Li <qi…@gmail.com> wrote:
>>>
>>> Hi,
>>>   I am new to this and trying to run the sample file you provided using visual studio. I got the following messages:
>>>
>>>   error LNK2019: unresolved external symbol _khpu referenced in function _main
>>>
>>>   I am not an expert on Visual Studio C++. It seems that I missed some settings. Can someone help? Thank you.
>>>
>>> Qi
>>>
>>>
>>> On Thursday, January 24, 2013 11:31:09 PM UTC-5, Jack Andrews wrote:
>>>>
>>>> link with c.obj (w32) here
>>>> http://code.kx.com/wsvn/code/kx/kdb%2B/w32/?#a735e1cacd939f9eedb1c43577954dd1f
>>>>
>>>> for the example http://code.kx.com/wsvn/code/contrib/wiki/csv.c,
>>>> compile like this:
>>>>
>>>>   cl -DKXVER=3 csv.c c.obj
>>>>
>>>> which should give you csv.exe
>>>>
>>>>
>>>> On Fri, Jan 25, 2013 at 7:06 AM, Yue Zhao <yzha…@gmail.com> wrote:
>>>> > Hi, folks,
>>>> >
>>>> > I have wrote a few C/C++ programs with interface to KDB, all of them needs
>>>> > to load c.dll at run time.
>>>> >
>>>> > I am wondering is there a way to write a standalone program that does not
>>>> > depend on any dynamic link library? so others without the dll file could
>>>> > also use my program?
>>>> >
>>>> > Best
>>>> >
>>>> > –
>>>> > Submitted via Google Groups

If you are using visual studio 2012 then you need to do the following:<o:p></o:p>

Right click on project,<o:p></o:p>

Properties,<o:p></o:p>

Linker,<o:p></o:p>

Input<o:p></o:p>

Additional dependencies<o:p></o:p>

Enter c.lib<o:p></o:p>

<o:p> </o:p>

HTH,<o:p></o:p>

Kim<o:p></o:p>

<o:p> </o:p>

<o:p> </o:p>

<o:p> </o:p>

Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Eric
Gesendet: Donnerstag, 21. April 2016 11:36
An: Kdb+ Personal Developers
Betreff: Re: [personal kdb+] Standalone C/C++ program using KDB ?<o:p></o:p>

<o:p> </o:p>

I am new to c.dll and encounter this error if my code uses the function “K ktj(I, J)”:

error LNK2019: unresolved external symbol _ktj

Did I miss anything?

? 2013?11?7??? UTC+8??9:55:08?Charles Skelton???<o:p></o:p>

you need to link with the kdb+ c-api library.<o:p></o:p>

For windows 32bit -<o:p></o:p>

http://kx.com/q/w32/c.lib which uses http://kx.com/q/w32/c.dll at run time<o:p></o:p>

or<o:p></o:p>

http://kx.com/q/w32/c.obj which does not depend on c.dll<o:p></o:p>

<o:p> </o:p>

For win 64bit, use files from http://kx.com/q/w64<o:p></o:p>

<o:p> </o:p>

On Thu, Nov 7, 2013 at 2:41 PM, Qi Li <qi…@gmail.com> wrote:<o:p></o:p>

Hi,<o:p></o:p>

  I am new to this and trying to run the sample file you provided using visual studio. I got the following messages:<o:p></o:p>

<o:p> </o:p>

  error LNK2019: unresolved external symbol _khpu referenced in function _main<o:p></o:p>

<o:p> </o:p>

  I am not an expert on Visual Studio C++. It seems that I missed some settings. Can someone help? Thank you. <o:p></o:p>

<o:p> </o:p>

Qi<o:p></o:p>