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
`hello
`hello
Any ideas why I can run the code in the same process?
for a shared object, do not link with c.o as those functions etc already exist within the kdb+ process.
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,…)?
Apologies, the code above should read
K handle = kph((S)“localhost”, 5010);
K ret = k(handle, (S)“0N!`hello”, (K)0);
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+.
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
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
feed_handler.so: Mach-O dynamically linked shared library i386
Is my compilation messed up?
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
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)
i think you need
-undefined dynamic_lookup