OS X Yosemite R/qserver error

I want to transfer data from kdb 32bits to R on my iMac Yosemite 10.10.2. I compiled qserver.so using k.h and m64/c.o from the SVN repository. I can open the connection to my kdb instance but when I execute a command I get a segmentation fault:

R version 3.1.2 (2014-10-31) – “Pumpkin Helmet”

Copyright (C) 2014 The R Foundation for Statistical Computing

Platform: x86_64-apple-darwin10.8.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under certain conditions.

Type ‘license()’ or ‘licence()’ for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.

Type ‘contributors()’ for more information and

‘citation()’ on how to cite R or R packages in publications.

Type ‘demo()’ for some demos, ‘help()’ for on-line help, or

‘help.start()’ for an HTML browser interface to help.

Type ‘q()’ to quit R.

> > options(STERM=‘iESS’, str.dendrogram.last=“'”, editor=‘emacsclient’, show.error.locations=TRUE)

> source(“qserver.R”)

> k = open_connection(host=“iMac.local”, port=“5000”)

> t = execute(k, “select from t”)

 *** caught segfault ***

address 0x2, cause ‘memory not mapped’

Traceback:

 1: .Call(“kx_r_execute”, as.integer(connection), query)

 2: execute(k, “select from t”)

Possible actions:

1: abort (with core dump, if enabled)

2: normal R exit

3: exit R without saving workspace

4: exit R saving workspace

you will need a new comipler https://groups.google.com/d/msg/personal-kdbplus/Qz7NloyIHD8/rbeEhNorsJIJ

I recompiled qserver.so (now warnings, everything works fine) with gcc-4.8 but I still have the same problem.
I noticed the user in the linked post is using R 3.0.2, I have 3.1.2.

what was your compile line when invoking gcc?
specifically, what did you set KXVER to? Should be 3.

$ make

/usr/bin/R CMD /usr/local/bin/gcc-4.8 -g -O -fpic -m64   -shared -D KXVER=3 -I. -I/Library/Frameworks/R.framework/Resources/include base.c c.o -lpthread -L/Library/Frameworks/R.framework/Resources/lib -lR -o qserver.so

$ R --version

R version 3.1.2 (2014-10-31) – “Pumpkin Helmet”

Copyright (C) 2014 The R Foundation for Statistical Computing

Platform: x86_64-apple-darwin10.8.0 (64-bit)

what the the meta of t? Can you give an example t that fails?

the following steps worked ok for me. Can anyone else verify using the osx/gcc versions of Alberto’s system?

gcc version 4.7.1 (MacPorts gcc47 4.7.1_0+universal) 

System Version:Mac OS X 10.7.5 (11G63b)

$ svn checkout http://code.kx.com/svn/cookbook_code/r/

A    r/osx_qserver

A    r/osx_qserver/qtest.R

A    r/osx_qserver/qserver.R

A    r/osx_qserver/qserver.so

…

Checked out revision 1857.

$ cd r/osx_qserver/

$ ls

MakefileREADME.txtbase.cqserver.Rqserver.soqtest.R

$ wget http://kx.com/q/c/c/k.h

2015-02-21 12:38:09 (114 MB/s) - `k.h’ saved [3941/3941]

$ wget http://kx.com/q/m64/c.o

…

2015-02-21 12:38:15 (62.8 KB/s) - `c.o’ saved [50240/50240]

$ make

/usr/bin/R CMD gcc -g -O -fpic -m64   -shared -D KXVER=3 -I. -I/Library/Frameworks/R.framework/Resources/include base.c c.o -lpthread -L/Library/Frameworks/R.framework/Resources/lib -lR -o qserver.so

$ cp qserver.so $QHOME/m64

$ r

R version 3.1.2 (2014-10-31) – “Pumpkin Helmet”

Copyright (C) 2014 The R Foundation for Statistical Computing

Platform: x86_64-apple-darwin10.8.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.

You are welcome to redistribute it under certain conditions.

Type ‘license()’ or ‘licence()’ for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.

Type ‘contributors()’ for more information and

‘citation()’ on how to cite R or R packages in publications.

Type ‘demo()’ for some demos, ‘help()’ for on-line help, or

‘help.start()’ for an HTML browser interface to help.

Type ‘q()’ to quit R.

> source(“qserver.R”)

> k = open_connection(host=“127.0.0.1”, port=“5000”)

> t = execute(k, “select from (a:til 10)”)

> t

   a

1  0

2  1

3  2

4  3

5  4

6  5

7  6

8  7

9  8

10 9

> quit()

Save workspace image? [y/n/c]: n

I must have had some mismatch, after removing the previous directory and following the instructions it worked fine.

I had the same problem when compiling on OSX. The issue was solved by changing CFLAGS to 

CFLAGS=-m$(MS) -bundle -undefined dynamic_lookup -D KXVER=3

as indicated at http://code.kx.com/wiki/Cookbook/ExtendingWithC.