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