OS X을 사용 중이며 Homebrew와 함께 Gtk + 3 패키지를 설치했습니다.동적 라이브러리가로드되는 순서가 중요합니까?
brew install gtk+3
은 내가 ctypes
모듈 파이썬에서 설치 라이브러리를로드 할 수 있습니다.
$ python2.6
Python 2.6.9 (unknown, Oct 23 2015, 19:19:20)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> cdll.LoadLibrary('/usr/local/lib/libatk-1.0.0.dylib')
<CDLL '/usr/local/lib/libatk-1.0.0.dylib', handle 7fbd10f1a250 at 10aa>
>>> cdll.LoadLibrary('/usr/local/lib/libglib-2.0.0.dylib')
<CDLL '/usr/local/lib/libglib-2.0.0.dylib', handle 7fbd10f0ffb0 at 10aa22dd0>
>>> ^D
지금까지 그렇게 좋았습니다. 한 가지 저를 괴롭히는 것은 위의 두 라이브러리를 로드하려고 시도했지만 다른 순서로 심볼을 찾지 못하면 예외가 발생합니다.
$ python2.6
Python 2.6.9 (unknown, Oct 23 2015, 19:19:20)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import cdll
>>> cdll.LoadLibrary('/usr/local/lib/libglib-2.0.0.dylib')
<CDLL '/usr/local/lib/libglib-2.0.0.dylib', handle 7fad13d00d60 at 10a688210>
>>> cdll.LoadLibrary('/usr/local/lib/libatk-1.0.0.dylib')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ctypes/__init__.py", line 423, in LoadLibrary
return self._dlltype(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ctypes/__init__.py", line 345, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(/usr/local/lib/libatk-1.0.0.dylib, 6): Symbol not found: _g_free
Referenced from: /usr/local/lib/libatk-1.0.0.dylib
Expected in: flat namespace
in /usr/local/lib/libatk-1.0.0.dylib
>>> ^D
그래서,로드 atk
먼저, 다음 glib
, 작동합니다. 주위에있는 다른 방법은 그렇지 않습니다. 아무도이 동작을 설명 할 수 있습니까?
예, C 라이브러리는 순서 종속적이며 의존성은 나중에 의존성보다 시퀀스에 있습니다. C에서 (예를 들어) libs A B와 C를 사용하면 A에서 사용 된 기호 중 C에서 발견 된 것으로 간주되는 기호가 B에서 처음에 이름이 바뀐 interloper에 의해 마스크 처리됩니다. B C A로 주문하면 고장납니다. 여기서 libatk는 A이고 심볼은 _g_free이고 glib *는 나중에 _g_free 정의로 나중에로드해야합니다. 링커는 A의 _g_free 사용이 이후 라이브러리에서 만족해야한다고 추적합니다. –