gclib  437
Communications API for Galil controllers and PLCs
gclibo.md
1 # Rebuilding gclibo {#gclibo}
2 
3 gclib ships with a compiled version of the open source portion, *gclibo*.
4 However, if a source modification is desired, the following instructions will
5 help with recompiling this portion of the library.
6 
7 <!--- ********************************************************************* -->
8 ***
9 ## Windows
10 ***
11 <!--- ********************************************************************* -->
12 
13 For brevity, these instructions assume the default installation location of **C:\\Program Files (x86)\\Galil\\gclib** and a build type of **x86 (win32)**.
14 The following instructions were performed on *Visual Studio Professional 2015* and can be extended to other Visual Studio versions.
15 
16 ###Preparation
17 
18 Create a working directory. A convenient, empty, writable location, e.g.
19 
20  C:>mkdir %homepath%\Desktop\temp
21 
22 
23 \note
24 In this documentation, a single *greater-than* character (>) will indicate a command prompt at this working directory.
25 
26 Recompiling gclibo requires the source code for the open source compression library **zlib**.
27 This can be downloaded from the zlib website: **http://zlib.net/zlib1211.zip**.
28 
29 Extract the downloaded zlib source files to the working directory.
30 
31 Open *VS2015 x86 Native Tools Command Prompt* and navigate to the working directory.
32 
33  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>cd %homepath%\Desktop\temp
34  C:\Users\user\Desktop\temp>dir /b
35  zlib-1.2.11
36 
37 ###Copy files
38 
39 ####Set an environment variable for the base path.
40 
41  >set base="C:\Program Files (x86)\Galil\gclib"
42 
43 ####Set an environment variable for the zlib base path.
44 
45  >set zlib="%CD%\zlib-1.2.11"
46 
47 ####Copy the gclibo source files.
48 
49  >copy %base%\source\gclibo\*.c .
50  C:\Program Files (x86)\Galil\gclib\source\gclibo\arrays.c
51  C:\Program Files (x86)\Galil\gclib\source\gclibo\gclibo.c
52  2 file(s) copied.
53 
54 
55 ###Modify source
56 Make any necessary changes. For this example, the GInfo() function was changed from
57 
58 \code{.c}
59 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
60 {
61  return GUtility(g, G_UTIL_INFO, info, &info_len);
62 }
63 \endcode
64 
65 to
66 
67 \code{.c}
68 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
69 {
70  strncpy(info, "My controller", info_len);
71  return G_NO_ERROR;
72  //return GUtility(g, G_UTIL_INFO, info, &info_len);
73 }
74 \endcode
75 
76 ###Compile and copy
77 
78 ####Compile the source code.
79 
80  >cl -c *.c %zlib%\*.c -I %base%\include -I %zlib% -DBUILDING_GCLIB
81 
82 ####Link the binaries.
83 
84  >link /DLL *.obj %base%\lib\dynamic\x86\gclib.lib /OUT:gclibo.dll
85 
86 ####Copy
87 Copy back to the installation location from the file explorer. This will require administrator privileges.
88 
89 * Copy gclibo.lib to "C:\Program Files (x86)\Galil\gclib\lib\dynamic\x86"
90 * Copy gclibo.dll to "C:\Program Files (x86)\Galil\gclib\dll\x86"
91 
92 ###Test
93 
94 ####Copy simple example
95 
96  >copy %base%\examples\cpp\x_simple.c .
97 
98 ####Edit GOpen() call as necessary.
99 ####Compile
100 
101  >cl x_simple.c %base%\lib\dynamic\x86\*.lib -I %base%\include
102 
103 ####Set Path to DLL
104 
105  >set PATH=%base%\dll\x86\;%PATH%
106 
107 ####Execute
108 
109  >x_simple.exe
110  rc: 0
111  version: 85.60.138
112  rc: 0
113  rc: 0
114  info: My controller
115  rc: 0
116  response: 355000958.0000
117  :
118 
119 
120 
121 
122 <!--- ********************************************************************* -->
123 ***
124 ## Linux
125 ***
126 <!--- ********************************************************************* -->
127 
128 Recompiling gclibo requires the source code for the open source compression library **zlib**.
129 Make will automatically download the needed project from the zlib website: **https://www.zlib.net/**.
130 
131 ###Copy files
132 
133  $ mkdir test
134  $ cd test
135  $ tar -xzf /usr/share/doc/gclib/src/gclibo_src.tar.gz
136  $ cp /usr/include/gclib*.h .
137 
138 ###Modify source
139 Make any necessary changes. For this example, the GInfo() function was changed from
140 
141 \code{.c}
142 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
143 {
144  return GUtility(g, G_UTIL_INFO, info, &info_len);
145 }
146 \endcode
147 
148 to
149 
150 \code{.c}
151 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
152 {
153  strncpy(info, "My controller", info_len);
154  return G_NO_ERROR;
155  //return GUtility(g, G_UTIL_INFO, info, &info_len);
156 }
157 \endcode
158 
159 ###Make and install
160 
161  # make install -f makefile_gclibo
162  Acquiring zlib
163  wget -q http://zlib.net/zlib-1.2.11.tar.gz
164  shasum -a 256 -c zlib.sha256
165  zlib-1.2.11.tar.gz: OK
166  tar -xzf zlib-1.2.11.tar.gz
167  Compiling zlib
168  gcc -c -Wall -w -fPIC -fvisibility=hidden -DBUILDING_GCLIB -DHAVE_VISIBILITY zlib-1.2.11/*.c
169  Compiling open source component, libgclibo.so.0.0
170  gcc -Izlib-1.2.11 -c -Wall -Werror -fPIC -fvisibility=hidden -DBUILDING_GCLIB -DHAVE_VISIBILITY gclibo.c arrays.c
171  Linking open source component into shared library.
172  gcc -shared -o libgclibo.so.0.0 *.o -lgclib -L. -Wl,-rpath=/usr/lib -Wl,-soname=libgclibo.so.0
173  strip --strip-unneeded libgclibo.so.0.0
174  Installing libgclibo.so.0.0
175  install -m 755 libgclibo.so.0.0 /usr/lib
176  ldconfig
177  # make clean -f makefile_gclibo
178  Cleaning project...
179 
180 
181 ###Test
182 
183 ####Extract simple example
184 
185  $ tar -xzf /usr/share/doc/gclib/src/gclib_examples.tar.gz x_simple.c
186 
187 #### Edit GOpen() call as necessary.
188 #### Compile
189 
190  $ gcc x_simple.c -Wall -Werror -lgclib -lgclibo -o simple
191 
192 ####Execute
193 
194  $ ./simple
195  rc: 0
196  version: 85.60.131
197  rc: 0
198  rc: 0
199  info: My controller
200  rc: 0
201  response: 182879322.0000
202  :
203 
204 
205 <!--- ********************************************************************* -->
206 ***
207 ## OS X
208 ***
209 <!--- ********************************************************************* -->
210 
211 
212 ###Copy files
213 
214  $ mkdir test
215  $ cd test
216  $ tar -xvf /Applications/gclib/source/gclibo_src.tar.gz x gclibo.h
217  x gclibo.c
218  x arrays.c
219  x makefile_gclibo
220  $ cp /Applications/gclib/include/* .
221  $ cp /Applications/gclib/dylib/gclib.0.dylib .
222  $ ls
223  arrays.c gclib.h gclib_record.h gclibo.h
224  gclib.0.dylib gclib_errors.h gclibo.c makefile_gclibo
225 
226 
227 ###Modify source
228 Make any necessary changes. For this example, the GInfo() function was changed from
229 
230 \code{.c}
231 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
232 {
233  return GUtility(g, G_UTIL_INFO, info, &info_len);
234 }
235 \endcode
236 
237 to
238 
239 \code{.c}
240 GReturn GCALL GInfo(GCon g, GCStringOut info, GSize info_len)
241 {
242  strncpy(info, "My controller", info_len);
243  return G_NO_ERROR;
244  //return GUtility(g, G_UTIL_INFO, info, &info_len);
245 }
246 \endcode
247 
248 ###Make and install
249 
250  $ make -f makefile_gclibo
251  Open source component, gclibo.0.dylib
252  Compiling open source component.
253  gcc -c -Wall -Werror -fPIC -fvisibility=hidden -DBUILDING_GCLIB -DHAVE_VISIBILITY *.c
254  Linking open source component into shared library.
255  gcc -dynamiclib -o gclibo.0.dylib *.o gclib.0.dylib
256  strip -u -r gclibo.0.dylib
257  Cleaning up.
258  $ make install -f makefile_gclibo
259  Installing gclibo.0.dylib
260  cp gclibo.0.dylib /Applications/gclib/dylib
261  $ make clean -f makefile_gclibo
262  Cleaning project...
263 
264 
265 ###Test
266 
267 ####Extract simple example
268 
269  $ tar -xzf /Applications/gclib/examples/gclib_examples.tar.gz x_simple.c
270 
271 #### Edit GOpen() call as necessary.
272 #### Compile
273 
274  $ gcc x_simple.c -Wall -Werror gclib.0.dylib gclibo.0.dylib -o simple
275 
276 ####Execute
277 
278  $ ./simple
279  rc: 0
280  version: 127.110.253
281  rc: 0
282  rc: 0
283  info: My controller
284  rc: 0
285  response: 182879322.0000
286  :
287 
288