Problems extending with c, shared object file not found [linux

So I’m trying to have a c function “start” which launches a java program using a system call:
Here’s what it looks like

#define KXVER 3
#include"k.h"
#include <stdlib.h>
#include <stdio.h>

void start(K something)
{
    printf(“starting java”);
    system(“java Prog hello there”); 
}

I compiled this as bar.so , using the command shown on Cookbook/ExtendingwtihC on the wiki, and placed it in my ~/q/ directory along with Prog.class.
(The only thing Prog.class does is print out its arguments).
The compilation was fine, there was no issue with k.h or anything else.

But when I try to call the function within q using

q)start: bar 2:(start;1)

I get an error saying:

'bar.so: cannot open shared object file: No such file or directory

I’ve tried putting the .so and .class files pretty much everywhere, inside l32, in the home directory, etc. but I still get this error.
Ive set my QHOME variable to /q/, and echoing $QHOME shows that.

I have no idea what to do next, and I really need this to work, so any help will be greatly appreciated.

Thanks

Adnan,

Did you add .so file location to LD_LIBRARY_PATH?

Thanks,
Pawel Tryfon

2013/12/22 Adnan G <adnan.gazi01@gmail.com>

So I’m trying to have a c function “start” which launches a java program using a system call:
Here’s what it looks like

#define KXVER 3
#include"k.h"
#include <stdlib.h>
#include <stdio.h>

void start(K something)
{
    printf(“starting java”);
    system(“java Prog hello there”); 
}

I compiled this as bar.so , using the command shown on Cookbook/ExtendingwtihC on the wiki, and placed it in my ~/q/ directory along with Prog.class.
(The only thing Prog.class does is print out its arguments).
The compilation was fine, there was no issue with k.h or anything else.

But when I try to call the function within q using

q)start: bar 2:(start;1)

I get an error saying:

'bar.so: cannot open shared object file: No such file or directory

I’ve tried putting the .so and .class files pretty much everywhere, inside l32, in the home directory, etc. but I still get this error.
Ive set my QHOME variable to /q/, and echoing $QHOME shows that.

I have no idea what to do next, and I really need this to work, so any help will be greatly appreciated.

Thanks




Submitted via Google Groups

echo $LD_LIBRARY_PATH

produces nothing, so it’s empty right?

How would I add the location? Do I just export ~/q/ to the name of the variable?

Do

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/lib/directory

HTH,

Pawel Tryfon

2013/12/22 Adnan G <adnan.gazi01@gmail.com>

echo $LD_LIBRARY_PATH

produces nothing, so it’s empty right?

How would I add the location? Do I just export ~/q/ to the name of the variable?

ah ok thanks, looks like its able to find it. But I’m getting another error now:

q)bar 2:(start, 1)
'bar.so: wrong ELF class: ELFCLASS64

I’m running 64-bit java, and q is the 32-bit trial. Maybe that’s something to do with it?

it looks like you compiled your shared library to be 64bit.
If you are loading it into 32bit kdb+, you should compile with -m32 flag to gcc.

btw, your c function should return either null or a ptr to a valid kobject.

e.g.

K start(K something)
{
    printf(“starting java”);
    system(“java Prog hello there”);  
    return 0;
}

Thanks, looks like its trying to execute the .so file.
But I’m getting a code error when running this:

q)bar 2:(start;1)
code

The function in the .c file is this:

K start(K something)
{
    system(“java Prog hello there”);  
    return 0;
}

And also, executing

q)bar 2:(start;1)[`something]

gives a 'type error for any parameter I give it. Do you know why?


On Monday, December 23, 2013 11:25:40 AM UTC, Charles Skelton wrote:

it looks like you compiled your shared library to be 64bit.
If you are loading it into 32bit kdb+, you should compile with -m32 flag to gcc.

btw, your c function should return either null or a ptr to a valid kobject.

e.g.

K start(K something)
{
    printf(“starting java”);
    system(“java Prog hello there”);  
    return 0;
}

if you are loading into kdb+3.0 upwards, or using the latest c libs, use KXVER=3

otherwise use KXVER=2

The pre def at the top says

#define KXVER 3

But it was always like that. I still don’t know why its giving me a code error.

q)bar 2:(start;1)
code

is not an error. This is just the display for a function that is implemented in a shared library. e.g.

q)f:bar 2:(start;1)
q)f

code

the type error is from missing (), i.e.

q)(bar 2:(start;1))[`something]

otherwise it is doing 

q)(start;1)[something]

'type

Oh wow, you’re right, it worked. Thanks a lot!