Monday, June 29, 2015

NTL library: symbol(s) not found for architecture x86_64


It took me a few days to resolve this problem with the NTL library on Mac OS X.
http://www.shoup.net/ntl/doc/tour-unix.html

So I am going to share the solution with anyone who might run into this problem.

The error:

ph$ clang++ -v -g -O2   -o bv_scheme NTL_examples.o  -lm -lgmp -lntl
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o bv_scheme NTL_examples.o -lm -lgmp -lntl -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "NTL::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, NTL::ZZ const&)", referenced from:
      _main in NTL_examples.o
  "std::istream::get()", referenced from:
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
  "std::istream::peek()", referenced from:
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
  "std::ostream& std::ostream::_M_insert<long>(long)", referenced from:
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__sub_I_lip.c in libntl.a(lip.o)
      __GLOBAL__sub_I_tools.c in libntl.a(tools.o)
  "std::ios_base::Init::~Init()", referenced from:
      __GLOBAL__sub_I_lip.c in libntl.a(lip.o)
      __GLOBAL__sub_I_tools.c in libntl.a(tools.o)
  "std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
  "std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::cerr", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Because Mac OS X now using libc++ rather than libstdc++, so you will need to compile the NTL library with libc++. You have to force it to use the libc++ option. The new compiling steps:

1. ./configure  NTL_GMP_LIP=on
2. open makefile under src/ and change to the following
CXX=clang++
# A C++ compiler, e.g., g++, CC, xlC 
LDLIBS=-lm -lc++
# libraries for linking C++ programs

3. make & sudo make install

Then you should be able to use the NTL library natively in Mac OS X.

Thursday, May 21, 2015

Things about PhoneLab

I am starting this post to document things about PhoneLab (www.phone-lab.org). Hopefully you find it useful.
https://www.phone-lab.org/experiment/start/


Download source

Initialize the repo
repo init -u http://platform.phone-lab.org:8080/platform/manifest -b phonelab/android-4.4.4_r1/develop

actually download the code with
repo sync


Build the source


source build/envsetup.sh
lunch aosp_hammerhead-userdebug
Compile the code with multiple cores.
make -j4



Build the Cruncher tool

source: https://www.phone-lab.org/experiment/data/#cruncher


git clone http://platform.phone-lab.org:8080/p/phonelab/cruncher.git
cd cruncher/crunchersudo



add these packages to the packages.txt
gfortran
libblas-dev
liblas-bin
liblas-c-dev
libatlas-dev
libatlas-base-dev
 
 
xargs -a packages.txt apt-get install
sudo pip install -r requirements.txt

Monday, April 13, 2015

node-red-contrib-bean installation error

> xpc-connection@0.1.3 install /Users/ph/.node-red/node_modules/node-red-contrib-bean/node_modules/ble-bean/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

  CXX(target) Release/obj.target/binding/src/XpcConnection.o
cc1plus: error: argument to '-O' should be a non-negative integer, 'g', 's' or 'fast'
make: *** [Release/obj.target/binding/src/XpcConnection.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Darwin 14.3.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/ph/.node-red/node_modules/node-red-contrib-bean/node_modules/ble-bean/node_modules/noble/node_modules/xpc-connection
gyp ERR! node -v v0.10.36
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok 
npm WARN optional dep failed, continuing xpc-connection@0.1.3

> noble@0.3.13 install /Users/ph/.node-red/node_modules/node-red-contrib-bean/node_modules/ble-bean/node_modules/noble
> node-gyp rebuild

  LINK(target) Release/hci-ble
  LINK(target) Release/hci-ble: Finished
  LINK(target) Release/l2cap-ble
  LINK(target) Release/l2cap-ble: Finished
node-red-contrib-bean@0.3.2 .node-red/node_modules/node-red-contrib-bean

└── ble-bean@2.1.0 (noble-device@0.1.3, crc@2.1.1, noble@0.3.13)


This is because the use of wrong GCC, as documented in 
https://github.com/sandeepmistry/node-xpc-connection/issues/2

$ which gcc
/usr/bin/gcc
Try setting the path, just before npm install:
export PATH=/usr/bin:$PATH

Tuesday, December 9, 2014

Adafruit kernel module for PWM for RaspberryPi

I was trying to use the Adafruit kernel source to build my customized kernel. But for some reasons, the USB hub was not working after installing the kernel. So I spent sometime to extract the kernel modules from Adafruit from their source tree.

Here is the patch that I generate for official RaspberryPi kernel source tree.


Wednesday, November 12, 2014

Thursday, October 23, 2014

Beautify Linux Screen session


Screen is a useful too to maintain remote SSH sessions while working with embedded devices. If you want to have nice and informative screen sessions, you can add the following to the ~/.screenrc file.

autodetach on
startup_message off
hardstatus alwayslastline
shelltitle 'bash'

hardstatus string '%{gk}[%{wk}%?%-Lw%?%{=b kR}(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= w}%?%+Lw%?%? %{g}][%{d}%l%{g}][ %{= w}%Y/%m/%d %0C:%s%a%{g} ]%{W}'

Tuesday, October 21, 2014

Updating MacPort to Yosemite

I was trying to install a package from MacPort and realized my port installation is broken. To install a new version, I have to recompile it from source.

I follow the SVN path.
https://guide.macports.org/#installing.macports.subversion

The compile is fine, no problem at all. Assume you have everything installed for compilation.

At the end, you might want to upgrade all outdated packages. then You will have a problem like this.

$ sudo port upgrade outdated
--->  Computing dependencies for cmake
--->  Configuring cmake
Error: Failed to configure cmake: configure failure: command execution failed
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_devel_cmake/cmake/main.log for details.
Error: Follow http://guide.macports.org/#project.tickets to report a bug.

CSs-MacBook-Pro:base ph$ more /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_devel_cmake/cmake/main.log

To solve the problem, you will need to update your xCode SDK. Just go to apple developer site and update it. After that, you are rock.

You will have another problem with gcc46.


$ sudo port upgrade outdated
Password:
--->  Computing dependencies for gcc46
--->  Building gcc46
Error: Failed to build gcc46: command execution failed
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_gcc46/gcc46/main.log for details.

Error: Follow http://guide.macports.org/#project.tickets to report a bug.

I went pass this problem with installing gcc49 and remove gcc46.

sudo port install gcc49
sudo port uninstall gcc46

RISC-v emulator

Changes are based on https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html For Ubuntu/Debian, in addition to sud...