Unable to compile on mac osx . Below is the c code that I have in my a.c file
#define KXVER 3
#include"k.h"
K f(K x){return ki(x->i+1);} // q calls c
K g(K x){return k(0,“1+”,r1(x),0);} // c calls q
I downloaded http://kx.com/q/l64/c.o and also downloaded http://kx.com/q/l32/c.o since I wasn’t sure which one is it that I will need. I then use the following command to compile:
gcc -o myprog a.c c.o
I am currently getting the following error:
ld: warning: ignoring file c.o, file was built for unsupported file format ( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) which is not the architecture being linked (x86_64): c.o
Undefined symbols for architecture x86_64:
“_k”, referenced from:
_g in a-dbd22b.o
“_ki”, referenced from:
_f in a-dbd22b.o
“_main”, referenced from:
implicit entry/start for main executable
“_r1”, referenced from:
_g in a-dbd22b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can you please help me understand what am I doing wrong?
I think you maybe need to be using the mac versions of the files located at:
http://code.kx.com/svn/kx/kdb+/m32 (for 32 bit binaries)
or
http://code.kx.com/svn/kx/kdb+/m64 (for 64 bit binaries)
when creating a shared lib to load into kdb+ do not link with c.o.
see http://code.kx.com/wiki/Cookbook/ExtendingWithC
Thank you! that worked. Had to also upgrade to gcc 4.8 and get libgmp and other dependencies upgraded and properly symlinked before getting it all to work. Thanks again!
Just to clarify in case you are still using c.o to build the shared library…as Charles mentioned, you don’t need to link against c.o for shared libraries
that will be loaded into kdb+ (e.g the a.c example code). Swapping the linux c.o file with the mac version will have solved your compilation error, but
it will increase the size of your library for no reason (kdb+ will have already loaded these definitions). It’s only in the case where you want to build
binaries that won’t be loaded into kdb+, as in the c.c example, that you need to link against c.o
I tried building the shared library as u suggested but that doesn’t compile for me when i use gcc4.8 . Below is my compile command:
gcc-4.8 -shared testshared.c -o test.so
testshared.c contains the following:
#define KXVER 3
#include “k.h”
K g(K x){return k(0,“1+”,r1(x),0);} // c calls q
Not really sure what I could be doing wrong?
on the link I posted, you can see an example compilation command for osx
gcc -bundle -undefined dynamic_lookup bar.c -o bar.so
wow Charles! That really worked! Thanks a ton!