4/28/2005 02:18:00 pm|W|P|CHERUB|W|P|See 184 Euro trip pics on my msn space.
http://spaces.msn.com/members/sg71cherub/|W|P|111469432964369723|W|P|My MSN SPACE|W|P|11/02/2005 02:21:00 pm|W|P|Anny|W|P|When I found your blog CHERUB I spent more time on it than I usually would when browsing, so congratulations, and also on My MSN SPACE. My own work is focussed on organization skill and organization skill too. Nathan11/20/2005 03:37:00 am|W|P|Anny|W|P|Very useful CHERUB, I can use what you've got here on My MSN SPACE as well as your other stuff for the research we're doing for organize your home. Cheers, Anny.11/20/2005 02:59:00 pm|W|P|Anny|W|P|Just wanted to say that I've sent some notes I gathered from your blog including My MSN SPACE for research on organize computer files which I'm helping with, with so thanks a lot CHERUB. Anny.11/21/2005 12:48:00 pm|W|P|Anny|W|P|I'm researching for organize your life and this on My MSN SPACE is useful so thanks CHERUB. Anny11/22/2005 06:18:00 am|W|P|Anny|W|P|Just wanted to say that I've sent some notes I gathered from your blog including My MSN SPACE for research on organize office which I'm helping with, with so thanks a lot CHERUB. Anny.11/26/2005 09:38:00 pm|W|P|Anny|W|P|CHERUB I've enjoyed this on My MSN SPACE and it's been useful for our own project on ##LINK#. Thanks. Anny.4/28/2005 01:23:00 pm|W|P|CHERUB|W|P|As a novice to Visual C++, people may only know about coding itself, but know little about the whole compiling stuffs. Here, I’d like to explicitly share my recent experience in compiling GSL 1.6 into a static library.
1. Link to the following website: http://sources.redhat.com/gsl/ to download the most recent version of GSL which should be 1.6. Expand gsl-1.6.tar to the ..\temp\gsl-1.6, so we may obtain all the source files of GSL. (e.g. c:\tmep\gsl-1.6)
2. What we are going to do is to build these source into a static library that we may simply include such a library to utilize the necessary mathematical routines or data structures that GSL has provided. Before we start the complex compiling work, let us organize the source files in advantage. Using Windows explorer to search the whole folder gsl-1.6 for files pertaining to key words: “makefile.*”, “TODO”, “Changelog”, and “test*.*”. Delete all the matched files, since they are useless for the library. (As a record, there are 94 files matching keyword “makefile.*”, 29 files matching keyword “TODO”, 45 files matching keyword “Changelog”, and 141 files and a folder matching keyword “test*.*”.)
3. Search files that match keyword “gsl_*.h” in the folder gsl-1.6. These files are header files which would be included in the source files where GSL routines are applied. Create a folder named gsl in the path: ..\temp\. Move these header files into folder gsl. (There are 213 files found.)
4. Now, we have accomplished in organizing source files. Open MS Visual C++ to start our long compiling way.
5. New a “Win32 Static Library” project, named as gsl_lib, set location as ..\temp\, and ignore the other settings. After the project is automatically established by MFC wizard, it is necessary to adjust some environment settings. Alt + F7, we open the “project setting” dialog. In page “Library”, change the “Output file name:” as “..\temp\gsl\msvcgsld.lib”. In menu Tools->Options, (“Options dialog”), we change some configures in the page “Directories” by adding path “..\temp” and “..\temp\gsl-1.6” into “Includes files”. Meanwhile, clear all the other non-relative paths.
6. The last thing to be prepared for starting the kernel work is the config.h file. config.h is used to guide the compiler to compile and link the source files. It may provide different preprocessor configurations. The fault preprocessor header may cause fatal error during compiling procedure. We are going to fight with it, modify it to fit the Visual C++ compiler and MS systems environments throughout the whole compiling procedure. As the attachment of this article, I’ve provided a row version config.h file which is former used for building GSL 1.5 static library. The truth proves that this file has to be modified a lot to successfully accomplish the whole compiling mission. OK, let’s copy the config.h file into folder ../temp/gsl-1.6.
7. Now, let’s start this tough work. According to the structure of GSL1.6, we firstly add a new folder in the Source Files of the project, named “blas”. Add all source files (C files) in the folder ../temp/gsl-1.6/blas into the folder “blas” of the project. Since the GSL is a very huge library including variant routines covering nearly every facet of mathematics, we can not hope we could compile all the numerous source codes together at once. The best way is to add packages one by one into the library, to limit the compiling errors to minimum. F7 to compile the project. OOPS! If you, the reader, using the same version and the same environment setting as mine, Visual C++ 6.0 development environment now reports 102 errors! However, be cool! The errors comes form the very beginning of gsl_pow_int.h. It’s because of the keyword “inline”. Forget those syntax errors, they are rubbish reports, or I may say they are consequential errors. By requiring helps to MSDN (online version, http://msdn.microsoft.com/library/), it responses the explanation of “inline” that “The inline keyword is available only in C++. The __inline and __forceinline keywords are available in both C and C++. For compatibility with previous versions, _inline is a synonym for __inline.” So, string inline is not defined by default. Hence, the compiler can not recognize inline at all. By help of our experiences (mainly come from my supervisor), we now look into config.h, which is in charge of making compiling stuffs compatible to different compiler. Add preprocessor heard “#define inline __inline” into config.h, commenting with “/* PZ 25.04.2005 */” (It’s a good coding habit). Compile the project again, Creating library…, HAHA, we make it! From now on, we are going to modify some codes and some file’s name to fit the requirement of the compiler. Remember to make a very good record of these adjustments. I’d like to make a summary at the end of each step pertaining to modifications. (The format should be like: Sum: “filename” action of modification)
Sum: “config.h” ADD “#define inline _inline”
8. Though only one package is well build, it is a good start. The second one is “block”. Add a folder named “block” and add in the source files belong to that package. (It is a routine for every package, so I’ll not mention this procedure any more for the reason of saving pages.) Whatever, press F7 and see what will happen. Not bad, only 80 errors reported now, in addition with 8 warnings. The first reported error comes from inti_source.c. Again, experience tells us that inti_source.c may be a dependency source file, which means that such a file has been included in the other files belonging to the same package. It turns out that init.c contains a line of “#include “inti_source.c” ”. So, remove init_source.c from the Source Files. Analogically, we remove files with suffix “_source.c”. Compile successfully now! On compiling the package “block”, we accumulate the experience of handling with the dependencies.
9. The third one, “cblas”. Do not add the header files into the Source Files. F7! No Error report now, instead of 55 warnings. Luckily, all the warnings pertain to the conversion precision lost. Forget it!
10. “cdf”. We now meet new situations! Warning report is “‘log1p’ undefined”, which can not be ignored trivially. Looking back to the MSDN again, there is no record about log1p concerning with C/C++ reference. So, MSVC has no definition about this operation. Carefully looking through config.h, we may find out the following lines: “/* Define to 1 if you have the declaration of `log1p', and to 0 if you don't. */” which continued with a preprocessor head “#define HAVE_DECL_LOG1P 1”. Since MSVC has no definition of log1p, we may set the HAVE_DECL_LOG1P to 0. That’s it! The same thing happens to expm1, so do the similar modification to config.h. OOPS, there are still some errors and warnings reports! Try to delete bata_inc.c from the Source Files since it seems to be the source of errors. (Suspecting it to be dependency!) Bingo!
Sum: “config.h” MODIFY #define HAVE_DECL_LOG1P 0
“config.h” MODIFY #define HAVE_DECL_EXPM1 0
11. “cheb”. The source files “..\temp\gsl-1.6\cheb\init.c” and “..\temp\gsl-1.6\block\init.c” are both configured to produce the output file “..\temp\gsl_lib\debug\init.obj”. Obviously, MSVC compiler does not allow 2 source files having the same names, even they are in different folders. It’s easy to remove init.c from folder cheb, rename it into cheb_init.c, and add it in again.
Sum: “init.c” RENAME “cheb_init.c”
12. “combination”. Even after we changed init.c and file.c to proper names, there still one compiling error reported. As the error is relative to an undeclared function, it is indeed because of the preprocessor header again! Since function gsl_combination_get(…) has clearly defined in gsl_combination.h, on condition that the HAVE_INLINE_STATIC has defined, we may add a preprocessor header in config.h defining HAVE_INLINE_STATIC: “#ifndef HIDE_INLINE_STATIC”.
Sum: “init.c” RENAME “combination_init.c”
“file.c” RENAME “combination_file.c”
“config.c” ADD “#define HIDE_INLINE_STATIC”
13. “complex”. As discussed about log1p above, the same error report occurs. This time, it is about acosh and atanh, which are not defined in math.h. The solution is to define HAVE_DECL_ACOSH and HAVE_DECL_ATANH in config.h as 0 which means acosh and atanh are not defined by default. Why we could solve the compiling problem by modifying config.h in this way? It’s time to make a deeper exploration into config.h. Let’s look for the last part of config.h. There are codes in the following format:
#define acosh gsl_acosh
It’s clear that, if acosh or atanh are not defined by default (in math.h), GSL will substitute gsl function for these missing math functions.
Sum: “config.c” MODIFY “#define HAVE_DECL_ACOSH 0”
“config.c” MODIFY “#define HAVE_DECL_ATANH 0”
14. The folder const is empty. Ignore it!
Sum: “deriv.c” RENAME “deriv_deriv.c”
16. “dht” and “diff” can be compiled without obstacle.
17. Folder doc contains some documentaries which are not necessary included into the static library.
18. “eigen”. isnan is not defined now. Can you solve this now? If still not, refer to the SUM at the end of this step. Moreover, there still are 20 errors come from qrstep.c. It is mostly suspected as dependency. The proof of a source file being a dependency is that it is explicitly included in the other source files. So, the easiest way to find out all the dependencies in one package is looking for keyword “ #include “ ” in the package. Using menu Edit -> Find in Files, the search results show that qrstep.c is included in the other 4 files of eigen package, so it is a dependency. Remove it from the Source Files, and the compiling problem is overcome. At the end of this step, I’d like to make a complement that _isnan is defined by C/C++. So we may substitute the isnan with _isnan or leave the default setting of config.h which substitutes isnan with gsl_isnan.
Sum: “config.c” MODIFY “#define HAVE_DECL_ISNAN 0”
Optional “config.c” MODIFY “#define isnan _isnan”
19. The compiler is happy with “err”.
20. “fft”. 587 errors and 195 warning in total. Maybe it is the largest trouble we’ve ever met since we decide to give a try on this tough work. Follow me to handle with these errors. Firstly, remove all the dependencies from the Source Files. Only compare_source.c, dft.c, fft.c, real.c, signals.c are left. Secondly, there are a serial of very weird errors reported occurring in compare.h, beginning at FUNCTION(…). Obviously, FUNCTION(…) is a macro which defined in template_on.h. What’s this macro? What is the relationship with the template_on.h and these errors? Here, the weirdest, meanwhile a very important trouble shooting skill is emerging. However, package fft can not clearly explain how we find out where is the problem is and why we could solve the problem by that way. So, follow me, remove compare_source.c and real.c from the Souce Files in order to make the compiling successful. fft package is not well built! Remember it we’ll come back to face this problem later. (Refer to package matrix)
21. “fit” is OK and there is nothing inside folder gsl.
22. “histogram”. It’s time to rebuild the whole project. If you are strictly followed my steps, there are 148 warnings reported and which are all warning C4244. Ignore these precision lost warning.
Sum: “file.c” RENAME “histogram_file.c”
“init.c” RENAME “histogram_init.c”
23. “ieee-utils”. Only remove some dependencies.
24. “integration”. Since we’ve changed the filename and such file is also included in the other source files, we have to modify part of source file. However, it won’t hurt GSL’s functions and its honor. (However, it’s weird that we changed the name of reset.c in order to add it into the Source Files but we removed it out of the Source Files since it is dependency. So maybe, next time, dependencies checking should be done in advantage.)
Sum: “reset.c” RENAME “integration_reset.c”
“qagp.c” MODIFY “#include “integration_reset.c”
“qags.c” MODIFY “#include “integration_reset.c”
“qawo.c” MODIFY “#include “integration_reset.c”
Optional: DO NO MODIFICATION
Sum: < interpolation> “linear.c” RENAME “interpolation_linear.c”
26. “linalg”. There is a seemly ridicules non-uniform existing in exponential.c, of which the filename now is linalg_exponential.c. Generally speaking, the header file named like gsl_*.h are saved in folder gsl and included with the path /gsl/. In step 3, we have gathered all these header files into folder gsl. However, gsl_linalg.h is not normally included in linalg_exponential.c. Actually, though I am not very clear whether there is a bug or a special design, I simply modify the path of this sentence. See the SUM.
Sum: “exponential.c” RENAME “linalg_exponential.c”
< linalg> linalg_exponential.c“ MODIFY “#include ”
27. “matrix”. Take a deep breath. We are handling the biggest problem that I’ve met when I compiled the library for the first time. Removing dependencies, we’ll face to lots of errors reports come from rowcol_source.c and the others. If we thoroughly check these errors, we may discover that they are pertaining to a macro, FUNCTION and a keyword, complex. The following figure depicts how the macro FUNCTION works. Firstly, rowcol.c defines BASE_GSL_COMPLEX. Then, it includes template_on.h, which switches to the code block matching BASE_GSL_COMPLEX being defined. In this code block, template_on.h defines SHORT as complex. Meanwhile, it also defines the original structure of the macro FUNCTION in its later part. Next, rowcol.c includes rowcol_source.h, in which, the macro FUNCITON has certain parameters and a body. The macro FUNCTION follows template’s design to generate a function named gsl_matrix__complex_row(). Unfortunately, be ware that there are 2 under-lines between “matrix” and “complex” in the function’s name. By tracing the trail of the preprocessor header “#define”, we may find out what happens indeed. In template_on.h, SHORT is defined as complex. The preprocessor header performs the function as substituting string “SHORT” with string “complex” in the header or source files when compiling them. Nevertheless, rowcol.c also includes gsl_math.h, which includes math.h. Ridiculously, math.h has defined complex as _complex! So, the continuously substitutions results a very secret compiling bug, double under-line, only because MSVC’s stupid preprocessor.
Luckily, we discovered the origin of this problem. However, the way to solve it is not a trivial work at all. Thanks to my supervisor’s proficient memory, he recalled that an isolated library named WinGSL has already overcome this type of compile problem. Hope you could understand the serial lines modifications in template_on.h. (Refer to Sum) GSL is mainly coded in terms of UNIX gcc compiler instead of MSVC. This bug may only occur when compiling GSL with MSVC or may some other bugs occur when utilizing the other compilers. So far, in this step, we improved our understanding of the relationship between the preprocessor headers.
Sum: “copy.c” RENAME “matrix_copy.c”
“file.c” RENAME “matrix_file.c”
“init.c” RENAME “matrix_init.c”
“oper.c” RENAME “matrix_oper.c”
#define MSVCPP_MATH_COMPLEX complex
before “#elif defined (BASE_GSL_COMPLEX)”
#define complex MSVCPP_MATH_COMPLEX
after the whole “#elif”
28. “min”. Now, we meet a new error report pertaining to finite, which is also not defined in MSVC. However, _finite is well defined. The solution is routine illustrated above. However, config.h has given more complicated solution on keyword finite. We may omit those lines and add one line of “#define finite _finite”.
Sum: “config.h” MODIFY “#define finite _finite”
#define finite isfinite
#define finite gsl_finite
29. “monte” passes.
30. “multifit” passes after rename some source files.
Sum: “convergence.c” RENAME “multifit_convergence.c”
“fsolver.c” RENAME “multifit_fsolver.c”
31. “multimin” passes.
Sum: “convergence.c” RENAME “multimin_convergence.c”
“diff.c” RENAME “multimin_diff.c”
32. “multiroots” passes.
Sum: “convergence.c” RENAME “multiroots_convergence.c”
“fdfsolver.c” RENAME “multiroots_fdfsolver.c”
“fsolver.c” RENAME “multiroots_fsolver.c”
33. “ntuple”, “ode-initval”, “permutation”, “poly”, “qrng”, “randist”, “rng”, and “roots” pass.
Sum: “cscal.c” RENAME “ode-initval_cscal.c”
“file.c” RENAME “permutation_file.c”
“init.c” RENAME “permutation_init.c”
< poly> “eval.c” RENAME “poly_eval.c”
“weibull.c” RENAME “radist_weibull.c”
“beta.c” RENAME “randist_beta.c”
“cauchy.c” RENAME “randist_cauchy.c”
“chisq.c” RENAME “randist_chisq.c”
“exponential.c” RENAME “randist_exponential.c”
“exppow.c” RENAME “randist_exppow.c”
“fdist.c” RENAME “randist_fdist.c”
“flat.c” RENAME “randist_flat.c”
“gamma.c” RENAME “randist_gamma.c”
“gauss.c” RENAME “randist_gauss.c”
“laplace.c” RENAME “randist_laplace.c”
“logistic.c” RENAME “randist_logistic.c”
“lognormal.c” RENAME “randist_lognormal.c”
“pareto.c” RENAME “randist_pareto.c”
“rayleigh.c” RENAME “randist_rayleigh.c”
“tdist.c” RENAME “randist_tdist.c”
“file.c” RENAME “rng_file.c”
“brent.c” RENAME “roots_brent.c”
“convergence.c” RENAME “roots_convergence.c”
“fdfsolver.c” RENAME “roots_fdfsolver.c”
“fsolver.c” RENAME “roots_fsolver.c”
“newton.c” RENAME “roots_newton.c”
34. “siman”, “sort”, “specfunc” and “statistics” pass.
Sum: “sort.c” RENAME “sort_sort.c”
< specfunc> “beta.c” RENAME “specfunc_beta.c”
< specfunc> “gamma.c” RENAME “specfunc_gamma.c”
< specfunc> “hyperg.c” RENAME “specfunc_hyperg.c”
< statistics> “minmax.c” RENAME “statistics_minmax.c”
35. “sum”. levin_u.c includes gsl_test.h which has never appeared in the whole GSL. Omit this odd line.
Sum: “levin_u.c” COMMENT “#include ”
“Levin_utrunc.c” COMMENT ““#include ”
36. “sys” passes.
Sum: < sys> “hypot.c” RENAME “sys_hypot.c”
< sys> “minmax.c” RENAME “sys_minmax.c”
< sys> “pow_int.c” RENAME “sys_pow_int.c”
37. “util”. memcpy.c provides the body of routine memcpy() which has been well defined in C/C++. So, source files such as memcpy.c, memmove.c, and so on are all not necessary to be added in the library. If you are not sure which routines are defied by C/C++, look them into the MSDN! Moreover, there is not a routine named strdup, but _strdup exists. So, we could carefully comment the body of strdup.c, instead with a line like: “#define strdup _strdup”. At last, only placeholder.c is conserved.
Sum: “strdup.c” COMMENT the body
“strdup.c” ADD “#define strdup _strdup”
38. “vector” passes.
Sum: “copy.c” RENAME “vector_copy.c”
“file.c” RENAME “vector_file.c”
“init.c” RENAME “vector_init.c”
“minmax.c” RENAME “vector_minmax.c”
“oper.c” RENAME “vector_oper.c”
“prop.c” RENAME “vector_prop.c”
“swap.c” RENAME “vector_swap.c”
“view.c” RENAME “vector_view.c”
39. And finally, “wavelet” succeeds!
40. Find out msvcgsld.lib in folder gsl, which is my 3 hours work. Till now, the folder gsl can be included whenever you what to utilizing GSL numerous routines to ease your coding work.
If you, the reader, could follow the above step to overcome variant compiling problems and accomplish building a static library, you may have good mood on solving so many strange difficulties and having a little tiny deep insight of what on earth the compiler does and what on earth the preprocessor header is. Good LUCK for further exploring trip.|W|P|111469110889027089|W|P|How to compile a library? Step by Step|W|P|1/17/2006 06:10:00 am|W|P|teci|W|P|thanks! need winGSL for thesis...have yet to actually read ur post but i hope it helps...and even if it doesn't, thanks for the effort in sharing! :) God bless!!!