# running kdb from c compiling issues

**URL:** <https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [April 3, 2015, 12:11am UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678 "2015-04-03T00:11:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![varun\_umich](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@varun\_umich](https://forum.kx.com/u/varun_umich)\
**Post date:** [April 3, 2015, 12:11am UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/1 "2015-04-03T00:11:00Z")

</div>

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);}&nbsp; // q calls c  
> K g(K x){return k(0,“1+”,r1(x),0);} // c calls q

&nbsp;

I downloaded&nbsp;&nbsp;http://kx.com/q/l64/c.o&nbsp;and also downloaded&nbsp;http://kx.com/q/l32/c.o&nbsp;since I wasn’t sure which one is it that I will need. I then use the following command to compile:&nbsp;

> 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:  
> &nbsp; “\_k”, referenced from:  
> &nbsp; &nbsp; &nbsp; \_g in a-dbd22b.o  
> &nbsp; “\_ki”, referenced from:  
> &nbsp; &nbsp; &nbsp; \_f in a-dbd22b.o  
> &nbsp; “\_main”, referenced from:  
> &nbsp;&nbsp; &nbsp; implicit entry/start for main executable  
> &nbsp; “\_r1”, referenced from:  
> &nbsp; &nbsp; &nbsp; \_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?&nbsp;

---

<div class="post-metadata">

**Author:** ![mark\_rooney](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@mark\_rooney](https://forum.kx.com/u/mark_rooney)\
**Post date:** [April 3, 2015, 11:02am UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/2 "2015-04-03T11:02:00Z")

</div>

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)

---

<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:** [April 3, 2015, 11:28am UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/3 "2015-04-03T11:28:00Z")

</div>

when creating a shared lib to load into kdb+ do not link with c.o.

see&nbsp;http://code.kx.com/wiki/Cookbook/ExtendingWithC

---

<div class="post-metadata">

**Author:** ![varun\_umich](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@varun\_umich](https://forum.kx.com/u/varun_umich)\
**Post date:** [April 3, 2015, 2:23pm UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/4 "2015-04-03T14:23:00Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mark\_rooney](https://avatars.discourse-cdn.com/v4/letter/m/278dde/32.png) [@mark\_rooney](https://forum.kx.com/u/mark_rooney)\
**Post date:** [April 3, 2015, 4:03pm UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/5 "2015-04-03T16:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![varun\_umich](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@varun\_umich](https://forum.kx.com/u/varun_umich)\
**Post date:** [April 3, 2015, 4:14pm UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/6 "2015-04-03T16:14:00Z")

</div>

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:&nbsp;

> #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?&nbsp;

---

<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:** [April 4, 2015, 7:13am UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/7 "2015-04-04T07:13:00Z")

</div>

on the link I posted, you can see an example compilation command for osx

gcc -bundle -undefined dynamic\_lookup bar.c -o bar.so

---

<div class="post-metadata">

**Author:** ![varun\_umich](https://avatars.discourse-cdn.com/v4/letter/v/e5b9ba/32.png) [@varun\_umich](https://forum.kx.com/u/varun_umich)\
**Post date:** [April 4, 2015, 7:00pm UTC](https://forum.kx.com/t/running-kdb-from-c-compiling-issues/9678/8 "2015-04-04T19:00:00Z")

</div>

wow Charles! That really worked! Thanks a ton!
