rivella50 / talib-ruby

Ruby Wrapper for the Technical Analysis Library ta-lib
55 stars 31 forks source link

undefined symbol: TA_GetFuncHandle #6

Closed tonkla closed 11 years ago

tonkla commented 11 years ago

I've installed ta-lib on Ubuntu 12.10 via source code, then talib_ruby, it seems ok.

$ env ARCHFLAGS="-arch i386" gem install talib_ruby -- --with-talib-include=/usr/local/ta-lib/include/ta-lib --with-talib-lib=/usr/local/ta-lib/lib
Building native extensions.  This could take a while...
Successfully installed talib_ruby-1.0.4
1 gem installed

but got an error when run the example. I've no idea what to do next.

$ ruby example/ma.rb
ruby: symbol lookup error: /.../gems/talib_ruby-1.0.4/lib/talib.so: undefined symbol: TA_GetFuncHandle
rivella50 commented 11 years ago

Try to install the gem with sudo, i.e.

sudo env ARCHFLAGS="-arch i386" gem install talib_ruby ...
tonkla commented 11 years ago

I use RVM, no need to use sudo. Thanks.

rivella50 commented 11 years ago

I just tried on my OSX Mountain Lion again with RVM and Ruby 1.9.3 and it works without any problems. The only difference i see is that my GCC Version is older (4.2.1) than yours, but since it compiled and installed the gem it should work also on your machine. You're sure that you don't have a 64bit machine ? Since i don't have much time at the moment you would have to look yourself what could be the problem.

brianlong commented 11 years ago

There are known problems with Mac OS X, Ruby, and the newer GCC.

I recall there some patches available to help resolve the problem.

Check stackoverflow.com and you should find some posts there.

I hope that helps get you in the right direction.

On Apr 3, 2013, at 9:34 AM, Valentin Treu wrote:

I just tried on my OSX Mountain Lion again with RVM and Ruby 1.9.3 and it works without any problems. The only difference i see is that my GCC Version is older (4.2.1) than yours, but since it compiled and installed the gem it should work also on your machine. You're sure that you don't have a 64bit machine ? Since i don't have much time at the moment you would have to look yourself what could be the problem.

— Reply to this email directly or view it on GitHub.

rivella50 commented 11 years ago

Thank you, Brian. I remember that i've also heard about these problems. @tonkla: If you find a solution it would be nice if you could post a hint here, then others can profit as well. Thank you.

tonkla commented 11 years ago

The problem is about Linux's shared libraries. Some Python TA-Lib users got the similar error. Thanks for your cool work and kindly answers.

rmldj commented 11 years ago

I have exactly the same problem. However in my case the issue is not the same as in the Python TA-Lib discussion mentioned above. In my case /usr/local/lib is in the library search path and I can see that libta_lib.so is in the output of ldconfig -v

The talib-ruby installation went as follows:

romuald@erato ~ $ env ARCHFLAGS="-arch x86_64" gem install talib_ruby -- --with-talib-include=/usr/local/include/ta-lib --with-talib-lib=/usr/local/lib
Fetching: talib_ruby-1.0.5.gem (100%)
Building native extensions with: '--with-talib-include=/usr/local/include/ta-lib --with-talib-lib=/usr/local/lib'
This could take a while...
Successfully installed talib_ruby-1.0.5
Parsing documentation for talib_ruby-1.0.5
unable to convert "\xEC" from ASCII-8BIT to UTF-8 for lib/talib.so, skipping
Installing ri documentation for talib_ruby-1.0.5
1 gem installed

The example script failed as before

ruby: symbol lookup error: /home/romuald/.rvm/gems/ruby-2.0.0-p0/gems/talib_ruby-1.0.5/lib/talib.so: undefined symbol: TA_GetFuncHandle

The mkmf.log file opens with

 have_library: checking for TA_Initialize() in -lta_lib... -------------------- no

The final conftest in mkmf.log also gave some weird errors

"gcc -o conftest -I/home/romuald/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0/x86_64-linux -I/home/romuald/.rvm/rubies/ruby-2.0.0-p0/include/ruby-2.0.0/ruby/backward -I/home/romuald/.rvm/rubies/
ruby-2.0.0-p0/include/ruby-2.0.0 -I. -I/usr/local/include/ta-lib  -I/home/romuald/.rvm/usr/include    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-lon
g -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration  -fPIC conftest.c  -L. -L/home/romuald/.rvm/rubi
es/ruby-2.0.0-p0/lib -Wl,-R/home/romuald/.rvm/rubies/ruby-2.0.0-p0/lib -L/usr/local/lib -Wl,-R/usr/local/lib -L/home/romuald/.rvm/usr/lib -Wl,-R/home/romuald/.rvm/usr/lib -L. -fstack-protector -
rdynamic -Wl,-export-dynamic -L/home/romuald/.rvm/usr/lib  -Wl,-R/home/romuald/.rvm/usr/lib      -Wl,-R -Wl,/home/romuald/.rvm/rubies/ruby-2.0.0-p0/lib -L/home/romuald/.rvm/rubies/ruby-2.0.0-p0/
lib -lruby -lta_lib  -lpthread -lrt -ldl -lcrypt -lm   -lc"
conftest.c: In function ‘t’:
conftest.c:6:1: warning: implicit declaration of function ‘TA_Initialize’ [-Wimplicit-function-declaration]
/usr/local/lib/libta_lib.so: undefined reference to `sinh'
/usr/local/lib/libta_lib.so: undefined reference to `sincos'

...

/usr/local/lib/libta_lib.so: undefined reference to `floor'
collect2: error: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: /*top*/
4: int main(void) {return 0;}
5: extern int t(void);
6: int t(void) { TA_Initialize(); return 0; }
/* end */
rivella50 commented 11 years ago

I have never seen these errors before. Does this also happen with another ruby version (1.8.7 or 1.9.x) ? What operating system do you have ?

rmldj commented 11 years ago

I have linux mint 14. I used rvm to install ruby-2.0.0. I'll try to see if I can switch to an older version then.

rivella50 commented 11 years ago

That would be interesting. I can tell you that on my OSX Mountain Lion the library works fine for all current Ruby versions. Unfortunately i don't have a Linux environment here to test your problem.

rmldj commented 11 years ago

I just installed ruby-1.9.3 using rvm, switched to it and installed the talib-ruby gem. Unfortunately I get the same errors as before (apart from the ASCII-8BIT to UTF-8 issue which went away during installation).

rivella50 commented 11 years ago

Ok then it's not Ruby. Therefore there's something wrong (or missing) with how you installed talib or there's a problem with the (newer) gcc version you have on your system. Please check the links above tonkla provided. Perhaps you find there some hints how to get it work.

rmldj commented 11 years ago

Thanks! Indeed this is a problem with the Linux ta-lib installation (ta-lib-0.4.0-src.tar.gz from the talib download page). Finally I figured out that one has to compile the talib library with an additional flag for linking in the math library - this was not the default of .configure.

So I had to use

./configure  LDFLAGS="-lm"
make
sudo make install

After I did that, I reinstalled the talib-ruby gem and the example program is now working!

rivella50 commented 11 years ago

Very nice, i'm glad that it's working now on your machine, too. Thanks for the explanation, i'm sure others can profit from that.

tonkla commented 11 years ago

Thanks @rmldj for your solution. Adding LDFLAGS="-lm" works like a charm. Actually, I still can't solve this problem for talib_ruby. How do you find the clue? Thanks.

rmldj commented 11 years ago

So this does not solve the problem in your case? I looked at the mkmf.log log file in the build directory for the talib_ruby extension

.rvm/gems/ruby-2.0.0-p0/gems/talib_ruby-1.0.5/ext/talib

There, I had undefined references to mathematical functions in /usr/local/lib/libta_lib.so (see the excerpt in my first post).

tonkla commented 11 years ago

@rmldj Sorry, I mean since I have closed this issue. Now, my problem has been solved by your solution :+1:

WealthCity commented 9 years ago

Still getting this error after doing the above...

ruby: symbol lookup error: /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/talib_ruby-1.0.6/talib.so: undefined symbol: TA_GetFuncHandle

klepsydra commented 9 years ago

@WealthCity At first I had the same problem. It seemed that recompiling 'ta-lib' with the math library & reinstalling the ruby gem 'talib_ruby' didn't work.

So I tried cleaning my env in both steps, then is worked:

# cd /usr/local/src/ta-lib
# make clean  ## I had skipped this before the 1st time I recompiled/relinked with LDFLAGS="-lm" 
# (date; umask 000; set -x;  time ./configure  LDFLAGS="-lm"   --prefix=/usr/local; time make; time make install)  |tee -a /tmp/ruby.gem.update.log

# ldconfig -v |tee /tmp/ldconfig.log   # just in case.

$ gem uninstall   talib_ruby  # Previously I hadn't tried this either, before reinstalling.
$ (date; time gem install --verbose  talib_ruby  ) |tee -a /tmp/ruby.gem.update.log

Now for a quick test:

$  ruby -e "require 'talib_ruby'; l = TaLib::Function.new('MA') "

No more

ruby: symbol lookup error: /usr/local/rvm/gems/ruby-2.2.1/gems/talib_ruby-1.0.6/lib/talib.so: undefined symbol: TA_GetFuncHandle

so this means it must have worked.