-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
133 lines (91 loc) · 4.08 KB
/
Copy pathREADME
File metadata and controls
133 lines (91 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
This is a sample project that is used to demonstrate how to create a
shared library in Haskell that can be called from other programs.
E.g: python using ctypes, or C using dlopen.
This is currently tested and working with OS X Snow Leopard with 7.4.2
running Haskell Platform 2012.4.0.0 64-bit.
To use:
$ sh build-test.sh 1
$ python test.py
build-test.sh contains a number of potential ways in which you could compile
a shared library (currently method '1' works correctly).
test.py uses ctypes to import and call the functions in the haskell shared library.
Test.hs contains some example functions.
Historical tests:
Previously there were problems on earlier version of the Haskell platform.
These experiments are documented below.
Tests:
1) OS X Snow Leopard GHC 7.0.4 from Haskell Platform 2011.4.0.0 64 bit
Build method #1:
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking Test.so ...
Undefined symbols:
"_environ", referenced from:
___hscore_environ in libHSbase-4.3.1.0.a(PrelIOUtils.o)
(maybe you meant: ___hscore_environ)
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build method #2:
Implicit import declaration:
Could not find module `Prelude':
Perhaps you haven't installed the "dyn" libraries for package `base'?
Use -v to see a list of the files searched for.
Build method #3:
Implicit import declaration:
Could not find module `Prelude':
Perhaps you haven't installed the "dyn" libraries for package `base'?
Use -v to see a list of the files searched for.
Build method #4:
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking libTest.so ...
ld: pointer in read-only segment not allowed in slidable image, used in ___gmpn_modexact_1c_odd from /usr/local/lib/ghc-7.0.4/integer-gmp-0.2.0.3/libHSinteger-gmp-0.2.0.3.a(mode1o.o)
collect2: ld returned 1 exit status
Build method #5:
Implicit import declaration:
Could not find module `Prelude':
Perhaps you haven't installed the "dyn" libraries for package `base'?
Use -v to see a list of the files searched for.
Build method #6:
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking libTest.so ...
ld: pointer in read-only segment not allowed in slidable image, used in ___gmpn_modexact_1c_odd from /usr/local/lib/ghc-7.0.4/integer-gmp-0.2.0.3/libHSinteger-gmp-0.2.0.3.a(mode1o.o)
collect2: ld returned 1 exit status
2) OS X Snow Leopard GHC 7.0.4 from Haskell Platform 2011.4.0.0 32 bit
Build method #1:
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking Test.so ...
Undefined symbols:
"_environ", referenced from:
_environ$non_lazy_ptr in libHSbase-4.3.1.0.a(PrelIOUtils.o)
(maybe you meant: ___hscore_environ, _environ$non_lazy_ptr )
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build method #2:
benno@ff:~/haskell-shared-example% sh build-test.sh 2
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking Test.so ...
ld: unknown option: -optc
collect2: ld returned 1 exit status
Build method #3:
benno@ff:~/haskell-shared-example% sh build-test.sh 3
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking libTest.so ...
Success! in linking:
But, load time error:
Library not loaded: /usr/local/lib/ghc-7.0.4/base-4.3.1.0/libHSbase-4.3.1.0-ghc7.0.4.dylib
Build method #4:
Success in linking, but loading error:
OSError: dlopen(./libTest.so, 6): Symbol not found: _alloc_blocks_lim
Referenced from: /Volumes/BigDisk/Users/benno/haskell-shared-example/libTest.so
Expected in: flat namespace
Build method #5:
Success in linking, but loading error:
OSError: dlopen(./libTest.so, 6): Library not loaded: /usr/local/lib/ghc-7.0.4/base-4.3.1.0/libHSbase-4.3.1.0-ghc7.0.4.dylib
Referenced from: /Volumes/BigDisk/Users/benno/haskell-shared-example/libTest.so
Reason: image not found
Build method #6:
benno@ff:~/haskell-shared-example% sh build-test.sh 6
[1 of 1] Compiling Test ( Test.hs, Test.o )
Linking libTest.so ...
benno@ff:~/haskell-shared-example% arch -i386 /usr/bin/python2.6 test.py
<CDLL './libTest.so', handle 20a570 at 1f0090>
<_FuncPtr object at 0x1d3af8>