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