aerospike / aerospike-client-c

Aerospike C Client
Other
98 stars 103 forks source link

Trouble building on Mac with Xcode #58

Closed daveyostcom closed 7 years ago

daveyostcom commented 7 years ago

The README.md file could make life much easier for Mac users by providing a separate Mac section, which contains a ready-to-use shell script, as shown at the end of this report.

Using macOS 10.12.3 with Xcode 8.2.1, I tried to follow the instructions in the README.md file, as follows.

Start with this:

brew install openssl

Homebrew complains and suggests doing this, which doesn't seem to help (more later):

brew install --force openssl

Do this:

git clone --depth=1 https://github.com/aerospike/aerospike-client-c.git
cd aerospike-client-c
git submodule update --init
open project/client.xcworkspace

In Xcode, try to build aerospike-test (which is not the default when Xcode opens). Xcode complains 'lua.h' file not found

brew install lua

In Xcode, try to build aerospike-test. Xcode complains 'openssl/ssl.h' file not found

Do this by hand to get around brew's refusal to do so (above, despite the --force argument):

# All this is required for Xcode but not for make.
pushd /usr/local/include
ln -sf ../opt/openssl/include/openssl .
cd /usr/local/lib
ln -sf ../opt/openssl/lib/libcrypto.dylib \
       ../opt/openssl/lib/libcrypto.1.0.0.dylib .
ln -sf ../opt/openssl/lib/libssl.dylib \
       ../opt/openssl/lib/libssl.1.0.0.dylib    .     
popd

In Xcode, try to build aerospike-test. Xcode complains about lua symbols. Brian says that this is because the lua installed by Homebrew is too recent. So do this:

brew uninstall lua

In Xcode, try to build aerospike-test. Xcode complains 'lua.h' file not found again.

Do this workaround, so that Xcode can see the lua that comes with the client from the repo. The README.md doesn't say that even if you're going to be building with Xcode, you nevertheless have to run make. This was not at all obvious.

# First we have to run make to get the lua includes and libs ready for use.
make
# so that they can be put in /usr/local/

Incidentally, I wasted some time because I didn't expect make to build lua in its source tree:

lrwxrwx---  1 yost  wheel      14 2017-02-05.22:16:50 modules/lua/src/luaconf.h -> luaconf.h.orig
-rw-rw----  1 yost  wheel    9048 2017-02-05.22:16:52 modules/lua/src/lapi.o
-rw-rw----  1 yost  wheel    9120 2017-02-05.22:16:52 modules/lua/src/lauxlib.o
-rw-rw----  1 yost  wheel   16196 2017-02-05.22:16:52 modules/lua/src/lbaselib.o
-rw-rw----  1 yost  wheel   25160 2017-02-05.22:16:52 modules/lua/src/lcode.o
-rw-rw----  1 yost  wheel    1528 2017-02-05.22:16:53 modules/lua/src/ldblib.o
-rw-rw----  1 yost  wheel    4848 2017-02-05.22:16:53 modules/lua/src/ldebug.o
-rw-rw----  1 yost  wheel    1432 2017-02-05.22:16:53 modules/lua/src/ldo.o
-rw-rw----  1 yost  wheel   11816 2017-02-05.22:16:53 modules/lua/src/ldump.o
-rw-rw----  1 yost  wheel    8400 2017-02-05.22:16:53 modules/lua/src/lfunc.o
-rw-rw----  1 yost  wheel    3160 2017-02-05.22:16:53 modules/lua/src/lgc.o
-rw-rw----  1 yost  wheel    2596 2017-02-05.22:16:53 modules/lua/src/linit.o
-rw-rw----  1 yost  wheel    7164 2017-02-05.22:16:54 modules/lua/src/liolib.o
-rw-rw----  1 yost  wheel    2128 2017-02-05.22:16:54 modules/lua/src/llex.o
-rw-rw----  1 yost  wheel    8292 2017-02-05.22:16:54 modules/lua/src/lmathlib.o
-rw-rw----  1 yost  wheel    1776 2017-02-05.22:16:54 modules/lua/src/lmem.o
-rw-rw----  1 yost  wheel    3640 2017-02-05.22:16:54 modules/lua/src/loadlib.o
-rw-rw----  1 yost  wheel   22828 2017-02-05.22:16:54 modules/lua/src/lobject.o
-rw-rw----  1 yost  wheel    1656 2017-02-05.22:16:55 modules/lua/src/lopcodes.o
-rw-rw----  1 yost  wheel   13608 2017-02-05.22:16:55 modules/lua/src/loslib.o
-rw-rw----  1 yost  wheel    8008 2017-02-05.22:16:55 modules/lua/src/lparser.o
-rw-rw----  1 yost  wheel    8820 2017-02-05.22:16:55 modules/lua/src/lstate.o
-rw-rw----  1 yost  wheel   15496 2017-02-05.22:16:55 modules/lua/src/lstring.o
-rw-rw----  1 yost  wheel   11688 2017-02-05.22:16:55 modules/lua/src/lstrlib.o
-rw-rw----  1 yost  wheel   18328 2017-02-05.22:16:55 modules/lua/src/ltable.o
-rw-rw----  1 yost  wheel   14980 2017-02-05.22:16:55 modules/lua/src/ltablib.o
-rw-rw----  1 yost  wheel    5432 2017-02-05.22:16:56 modules/lua/src/ltm.o
-rw-rw----  1 yost  wheel    9572 2017-02-05.22:16:56 modules/lua/src/lua.o
-rw-rw----  1 yost  wheel    7536 2017-02-05.22:16:56 modules/lua/src/luac.o
-rw-rw----  1 yost  wheel   18460 2017-02-05.22:16:56 modules/lua/src/lundump.o
-rw-rw----  1 yost  wheel   10728 2017-02-05.22:16:56 modules/lua/src/lvm.o
-rw-rw----  1 yost  wheel    1768 2017-02-05.22:16:56 modules/lua/src/lzio.o
-rw-rw----  1 yost  wheel    4996 2017-02-05.22:16:57 modules/lua/src/print.o
-rwxrwx---  1 yost  wheel  180796 2017-02-05.22:16:56 modules/lua/src/lua
-rw-rw----  1 yost  wheel  278232 2017-02-05.22:16:56 modules/lua/src/liblua.a
-rwxrwx---  1 yost  wheel  127332 2017-02-05.22:16:57 modules/lua/src/luac

Now that make has built the right version of lua, do this:

cp -p modules/lua/src/liblua.a          /usr/local/lib      
cp -p modules/lua/src/lua.h \
      modules/lua/src/luaconf.h \
      modules/lua/src/luaconf.h.orig \
      modules/lua/src/lauxlib.h \
      modules/lua/src/lualib.h          /usr/local/include 

In Xcode, try to build aerospike-test. Xcode complains ld: library not found for -luv.

Do this (even though the README.md file implies that it's optional):

brew install libuv
brew install libev

In Xcode, try to build aerospike-test. Build Succeeded! (but with many warnings)

Xcode has many hard-coded paths to libs (mostly in red): xcode-lib-refs

Only the liblua.a and libev.a references work. The others don't work for path and version reasons. In any case, if these references are going to be here and made to work, they should probably be shared, either in the aerospike project or in a new aerospike-libs project.

Here are all of my workarounds, collected in one script:

if [[ $cleanfirst ]] ; then
  echo cleaning...
  brew uninstall libuv
  brew uninstall libev
  brew uninstall openssl
  rm -f /usr/local/include/openssl
  rm -f /usr/local/lib/lib{ssl,crypto}*.dylib  
  rm -f /usr/local/include/lua.h \
        /usr/local/include/luaconf.h \
        /usr/local/include/lualib.h \
        /usr/local/include/lauxlib.h \
        /usr/local/lib/liblua.a
  rm -rf aerospike-client-c
fi

# Both are required for Xcode; neither is required for make.
brew install libuv
brew install libev

# I had to do --force. Maybe others won't.
brew install --force openssl
(
    # All this is required for Xcode but not for make.
    cd /usr/local/include
    ln -sf ../opt/openssl/include/openssl .
    cd /usr/local/lib
    ln -sf ../opt/openssl/lib/libcrypto.dylib \
           ../opt/openssl/lib/libcrypto.1.0.0.dylib .
    ln -sf ../opt/openssl/lib/libssl.dylib \
           ../opt/openssl/lib/libssl.1.0.0.dylib    .     
)

git clone --depth=1 git@github.com:aerospike/aerospike-client-c.git
cd aerospike-client-c
git submodule update --init

# make -j doesn't work.
make

# 
cp -p modules/lua/src/liblua.a          /usr/local/lib      
cp -p modules/lua/src/lua.h \
      modules/lua/src/luaconf.h \
      modules/lua/src/luaconf.h.orig \
      modules/lua/src/lauxlib.h \
      modules/lua/src/lualib.h          /usr/local/include 

open project/client.xcworkspace
BrianNichols commented 7 years ago

Hi Dave,

I will need to obtain a machine with latest MacOS and XCode to test the recommended changes. This may take a couple of days.

I don't understand why libpthread.dylib and libz.dylib are not found in "/usr/lib". Will have to check latest MacOS.

libuv.a is only required if AS_USE_LIBUV is defined as a CFLAG in the xcode project. If this flag is not defined, the build and execute will work fine even though the library is red.

daveyostcom commented 7 years ago

Hi Brian,

Re libuv being required, try running my script with the “brew install libuv” commented out.

BrianNichols commented 7 years ago

I have reworked the xcode project files, added a prepare_xcode script and updated the readme. This will appear in the next release of the C client.

BrianNichols commented 7 years ago

C client 4.1.4 has been released:

http://www.aerospike.com/download/client/c/4.1.4/