Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcapstone.dylib is placed in the wrong location, causes errors with the python binding #74

Closed
ancat opened this issue Feb 18, 2014 · 13 comments

Comments

@ancat
Copy link

ancat commented Feb 18, 2014

The error:

2502:python jesus$ python test_x86.py
Traceback (most recent call last):
  File "test_x86.py", line 5, in <module>
    from capstone import *
  File "/Users/xxx/development/capstone-2.0/bindings/python/capstone/__init__.py", line 1, in <module>
    from capstone import Cs, CsError, cs_disasm_quick, cs_version, cs_support, CS_API_MAJOR, CS_API_MINOR, CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_MIPS, CS_ARCH_X86, CS_ARCH_PPC, CS_ARCH_ALL, CS_MODE_LITTLE_ENDIAN, CS_MODE_ARM, CS_MODE_THUMB, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT, CS_OPT_SYNTAX_INTEL, CS_OPT_SYNTAX_ATT, CS_OPT_SYNTAX_NOREGNAME, CS_OPT_DETAIL, CS_OPT_ON, CS_OPT_OFF, CS_MODE_16, CS_MODE_32, CS_MODE_64, CS_MODE_BIG_ENDIAN, CS_MODE_MICRO, CS_MODE_N64
  File "/Users/xxx/development/capstone-2.0/bindings/python/capstone/capstone.py", line 150, in <module>
    raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.

bindings/python/capstone.py when imported looks for libcapstone.dll, libcapstone.so, and libcapstone.dylib in a number of locations. There is a libcapstone.dylib file that is produced in the root directory of the project. Moving this to the same folder as capstone.py (in reality it should work anywhere as long as it's in $PATH) fixes the error. I faced this problem using both brew&pip and compiling from source. I did not have this issue on Linux.

@aquynh
Copy link
Collaborator

aquynh commented Feb 18, 2014

the point is that you have to install Capstone into your system before
running those Python tests.

$ make; $ sudo make install

similarly, brew/macports should be used to install the core before
installing from pip/easy_install. only after that, you can write Python
code.

see http://capstone-engine.org/documentation.html

thanks.

On Tue, Feb 18, 2014 at 1:34 PM, Omar notifications@github.com wrote:

The error:

2502:python jesus$ python test_x86.py
Traceback (most recent call last):
File "test_x86.py", line 5, in
from capstone import *
File "/Users/xxx/development/capstone-2.0/bindings/python/capstone/init.py", line 1, in
from capstone import Cs, CsError, cs_disasm_quick, cs_version, cs_support, CS_API_MAJOR, CS_API_MINOR, CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_MIPS, CS_ARCH_X86, CS_ARCH_PPC, CS_ARCH_ALL, CS_MODE_LITTLE_ENDIAN, CS_MODE_ARM, CS_MODE_THUMB, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT, CS_OPT_SYNTAX_INTEL, CS_OPT_SYNTAX_ATT, CS_OPT_SYNTAX_NOREGNAME, CS_OPT_DETAIL, CS_OPT_ON, CS_OPT_OFF, CS_MODE_16, CS_MODE_32, CS_MODE_64, CS_MODE_BIG_ENDIAN, CS_MODE_MICRO, CS_MODE_N64
File "/Users/xxx/development/capstone-2.0/bindings/python/capstone/capstone.py", line 150, in
raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.

bindings/python/capstone.py when imported looks for libcapstone.dll,
libcapstone.so, and libcapstone.dylib in a number of locations. There _is_a
libcapstone.dylib file that is produced in the root directory of the
project. Moving this to the same folder as capstone.py (in reality it
should work anywhere as long as it's in $PATH) fixes the error. I faced
this problem using both brew&pip and compiling from source. I did not have
this issue on Linux.

Reply to this email directly or view it on GitHubhttps://github.com//issues/74
.

@ancat
Copy link
Author

ancat commented Feb 18, 2014

I installed capstone using brew before installing the python bindings using pip.

502:~ jesus$ brew install capstone
==> Downloading http://capstone-engine.org/download/2.0/capstone-2.0.tgz
Already downloaded: /Library/Caches/Homebrew/capstone-2.0.tgz
==> ./make.sh
==> ./make.sh install
/usr/local/Cellar/capstone/2.0: 14 files, 6.9M, built in 4 seconds
2502:~ jesus$ sudo pip install capstone
Password:
Downloading/unpacking capstone
  Running setup.py egg_info for package capstone

Installing collected packages: capstone
  Running setup.py install for capstone

Successfully installed capstone
Cleaning up...
2502:~ jesus$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import capstone
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/capstone/__init__.py", line 1, in <module>
    from capstone import Cs, CsError, cs_disasm_quick, cs_version, cs_support, CS_API_MAJOR, CS_API_MINOR, CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_MIPS, CS_ARCH_X86, CS_ARCH_PPC, CS_ARCH_ALL, CS_MODE_LITTLE_ENDIAN, CS_MODE_ARM, CS_MODE_THUMB, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT, CS_OPT_SYNTAX_INTEL, CS_OPT_SYNTAX_ATT, CS_OPT_SYNTAX_NOREGNAME, CS_OPT_DETAIL, CS_OPT_ON, CS_OPT_OFF, CS_MODE_16, CS_MODE_32, CS_MODE_64, CS_MODE_BIG_ENDIAN, CS_MODE_MICRO, CS_MODE_N64
  File "/Library/Python/2.7/site-packages/capstone/capstone.py", line 150, in <module>
    raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.
>>>

@aquynh
Copy link
Collaborator

aquynh commented Feb 18, 2014

oh, you need to do some setup before using Python. the reason is brew put
the library in non-standard place.

the solution is to put the path of Capstone library into DYLD_LIBRARY_PATH,
so Python can find it.

can you try this command on command line, and report the result?

$ export DYLD_LIBRARY_PATH=/usr/local/opt/capstone/lib64/:$DYLD_LIBRARY_PATH

thanks.

On Tue, Feb 18, 2014 at 1:57 PM, Omar notifications@github.com wrote:

I installed capstone using brew before installing the python bindings
using pip.

502:~ jesus$ brew install capstone
==> Downloading http://capstone-engine.org/download/2.0/capstone-2.0.tgz
Already downloaded: /Library/Caches/Homebrew/capstone-2.0.tgz
==> ./make.sh
==> ./make.sh install
/usr/local/Cellar/capstone/2.0: 14 files, 6.9M, built in 4 seconds
2502:~ jesus$ sudo pip install capstone
Password:
Downloading/unpacking capstone
Running setup.py egg_info for package capstone

Installing collected packages: capstone
Running setup.py install for capstone

Successfully installed capstone
Cleaning up...
2502:~ jesus$ python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import capstone
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/capstone/init.py", line 1, in
from capstone import Cs, CsError, cs_disasm_quick, cs_version, cs_support, CS_API_MAJOR, CS_API_MINOR, CS_ARCH_ARM, CS_ARCH_ARM64, CS_ARCH_MIPS, CS_ARCH_X86, CS_ARCH_PPC, CS_ARCH_ALL, CS_MODE_LITTLE_ENDIAN, CS_MODE_ARM, CS_MODE_THUMB, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT, CS_OPT_SYNTAX_INTEL, CS_OPT_SYNTAX_ATT, CS_OPT_SYNTAX_NOREGNAME, CS_OPT_DETAIL, CS_OPT_ON, CS_OPT_OFF, CS_MODE_16, CS_MODE_32, CS_MODE_64, CS_MODE_BIG_ENDIAN, CS_MODE_MICRO, CS_MODE_N64
File "/Library/Python/2.7/site-packages/capstone/capstone.py", line 150, in
raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.

Reply to this email directly or view it on GitHubhttps://github.com//issues/74#issuecomment-35355159
.

@ancat
Copy link
Author

ancat commented Feb 18, 2014

This fixes the problem. I thought it was make.sh to blame, but it makes sense that it's brew's fault, since compiling from source actually does work. Thanks for the help.

@ancat ancat closed this as completed Feb 18, 2014
@aquynh
Copy link
Collaborator

aquynh commented Feb 18, 2014

no problem.

if you are doing anything cool with Capstone, just let us know :-)

thanks.

On Tue, Feb 18, 2014 at 2:44 PM, Omar notifications@github.com wrote:

This fixes the problem. I thought it was make.sh to blame, but it makes
sense that it's brew's fault, since compiling from source actually does
work. Thanks for the help.

Reply to this email directly or view it on GitHubhttps://github.com//issues/74#issuecomment-35356964
.

@itJunky
Copy link

itJunky commented Sep 15, 2014

i'm install capstone by pip in ubuntu 12, but i get same error! Why???

@aquynh
Copy link
Collaborator

aquynh commented Sep 16, 2014

On Tue, Sep 16, 2014 at 2:51 AM, Max notifications@github.com wrote:

i'm install capstone by pip in ubuntu 12, but i get same error! Why???

did you install the core yet? without the core, the Python binding will not
work.

if you did install the core, how to reproduce your problem?

thanks.

@aquynh
Copy link
Collaborator

aquynh commented Sep 16, 2014

On Tue, Sep 16, 2014 at 8:31 AM, Nguyen Anh Quynh aquynh@gmail.com wrote:

On Tue, Sep 16, 2014 at 2:51 AM, Max notifications@github.com wrote:

i'm install capstone by pip in ubuntu 12, but i get same error! Why???

did you install the core yet? without the core, the Python binding will
not work.

if you did install the core, how to reproduce your problem?

by the way, make sure to match the core's version with the binding's
version.
example: if you are using Python binding 2.1.2, you need the core 2.1.2.

thanks.

@upbit
Copy link

upbit commented Dec 2, 2014

Thanks! I just found brew install capstone install nothing but INSTALL_RECEIPT.json.

Finally I place libcapstone.dylib into /usr/local/opt/capstone/lib64/ and export:
$ export DYLD_LIBRARY_PATH=/usr/local/opt/capstone/lib64/:$DYLD_LIBRARY_PATH

It works again!

$ brew install capstone
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/capstone-3.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring capstone-3.0.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/capstone/3.0: 5 files, 28K

$ ls /usr/local/opt/capstone/
ChangeLog            INSTALL_RECEIPT.json LICENSE.TXT          README               TODO

$ cat INSTALL_RECEIPT.json
{"used_options":[],"unused_options":[],"built_as_bottle":true,"poured_from_bottle":true,"tapped_from":"Homebrew/homebrew","time":1416408096,"HEAD":"9921bc632ef7158656bba9dc89e2549ca04bb45a","stdlib":null,"compiler":"clang"}

@aquynh
Copy link
Collaborator

aquynh commented Dec 2, 2014

confirmed this issue & working on a fix for Brew formula now, thanks.

@aquynh
Copy link
Collaborator

aquynh commented Dec 2, 2014

this should be fixed now in Brew formula. can you update Brew (with brew update), then try to reinstall Capstone?

thanks.

@upbit
Copy link

upbit commented Dec 3, 2014

After reinstall Capstone 3.0_1, it fix now. Thanks for the great disassembly framework!

$ brew install capstone
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/capstone-3.0_1.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/capstone-3.0_1.yosemite.bottle.tar.gz
==> Pouring capstone-3.0_1.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/capstone/3.0_1: 18 files, 5.6M
$ cd /usr/local/Cellar/capstone/3.0_1/
heineko:3.0_1 zhou$ ls
ChangeLog            LICENSE.TXT          TODO                 lib
INSTALL_RECEIPT.json README               include

$ ll /usr/local/lib/libcapstone.*
lrwxr-xr-x  1 zhou  admin  48 12  3 08:34 /usr/local/lib/libcapstone.3.dylib -> ../Cellar/capstone/3.0_1/lib/libcapstone.3.dylib
lrwxr-xr-x  1 zhou  admin  42 12  3 08:34 /usr/local/lib/libcapstone.a -> ../Cellar/capstone/3.0_1/lib/libcapstone.a
lrwxr-xr-x  1 zhou  admin  46 12  3 08:34 /usr/local/lib/libcapstone.dylib -> ../Cellar/capstone/3.0_1/lib/libcapstone.dylib

@aquynh
Copy link
Collaborator

aquynh commented Dec 3, 2014

thanks for reporting the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants