# Error -128 calling k(0, ...) from same process

**URL:** <https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [September 5, 2014, 5:45pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045 "2014-09-05T17:45:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![samsogade](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@samsogade](https://forum.kx.com/u/samsogade)\
**Post date:** [September 5, 2014, 5:45pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/1 "2014-09-05T17:45:00Z")

</div>

In my shared object I have

K ret = k(0, (S)“0N!`hello”, (K)0);

If I call the above code from the current process I receive ret == -128 and ret-\>s will return (null). However, if I open two processes, one listening on port 5010 and another process with the code

K handle = kph((S)“localhost”, 5010);

K ret = k(0, (S)“0N!`hello”, (K)0);

There are no problems, and the process running on port 5010 will as expected print&nbsp;

`hello

`hello

Any ideas why I can run the code in the same process?

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [September 5, 2014, 5:50pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/2 "2014-09-05T17:50:00Z")

</div>

for a shared object, do not link with c.o as those functions etc already exist within the kdb+ process.

---

<div class="post-metadata">

**Author:** ![samsogade](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@samsogade](https://forum.kx.com/u/samsogade)\
**Post date:** [September 5, 2014, 6:08pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/3 "2014-09-05T18:08:00Z")

</div>

Thanks Charles. How can I compile anything without linking to c.o?

I can send the data from one q process to another, but not to itself where the shared object is loaded, i.e. k(0,…)?

---

<div class="post-metadata">

**Author:** ![samsogade](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@samsogade](https://forum.kx.com/u/samsogade)\
**Post date:** [September 5, 2014, 6:09pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/4 "2014-09-05T18:09:00Z")

</div>

Apologies, the code above should read

K handle = kph((S)“localhost”, 5010);

K ret = k(handle, (S)“0N!`hello”, (K)0);

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [September 5, 2014, 6:13pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/5 "2014-09-05T18:13:00Z")

</div>

to create a shared lib on linux using gcc, the cmd line for compiling would be

gcc -DKXVER=3 a.c -o a.so -fPIC -shared

the functions such as ktn etc are resolved when loading into kdb+.

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [September 5, 2014, 7:13pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/6 "2014-09-05T19:13:00Z")

</div>

btw, for developing shared libs, refer to

http://code.kx.com/wiki/Cookbook/ExtendingWithC

noting that if you are developing a lib to load into kdb+2.x define KXVER=2

and for v3.x define KXVER=3

---

<div class="post-metadata">

**Author:** ![samsogade](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@samsogade](https://forum.kx.com/u/samsogade)\
**Post date:** [September 11, 2014, 3:38pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/7 "2014-09-11T15:38:00Z")

</div>

Thanks a lot!

One more issue: My dynamic shared object does not contain any exported symbols. My C++ code contains some functions that are defined like extern “C” myfunc(). From the terminal I can see that myfunc() is not being exported:

nm -f feed\_handler.so

U dyld\_stub\_binder

file feed\_handler.so

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;feed\_handler.so: Mach-O dynamically linked shared library i386

Is my compilation messed up?

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [September 11, 2014, 4:59pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/8 "2014-09-11T16:59:00Z")

</div>

can you provide a very simple test cpp file, .e.g

#include"k.h"

extern “C” K f(K x){R (K)0;}

and your compile cmd line?

and compiler version

---

<div class="post-metadata">

**Author:** ![samsogade](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@samsogade](https://forum.kx.com/u/samsogade)\
**Post date:** [September 12, 2014, 6:24pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/9 "2014-09-12T18:24:00Z")

</div>

Ok, so I can compile your example. However, if I use other functions such as k(), ki(), khp(), etc. I’m getting ‘Undefined symbols’:

#include “k.h”

extern “C” K f(K x){R (K)0;}

extern “C” K add(K x,K y)

{

R ki(x-\>i+y-\>i);

}

compiling:

clang++ -DKXVER=3 -m32 -fPIC -shared -stdlib=libc++ -std=c++11 test.cpp -o test.so

Undefined symbols for architecture i386:

“\_ki”, referenced from:

\_add in test-d49315.o

ld: symbol(s) not found for architecture i386

clang: error: linker command failed with exit code 1 (use -v to see invocation)

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [September 12, 2014, 6:59pm UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/10 "2014-09-12T18:59:00Z")

</div>

i think you need

-undefined dynamic\_lookup&nbsp;

---

<div class="post-metadata">

**Author:** ![samsogade](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@samsogade](https://forum.kx.com/u/samsogade)\
**Post date:** [September 14, 2014, 11:53am UTC](https://forum.kx.com/t/error-128-calling-k-0-from-same-process/9045/11 "2014-09-14T11:53:00Z")

</div>

Thanks a lot Charles
