Troubleshooting TOSSIM compilation
TOSSIM is a C/C++ shared library with an optional Python translation layer. Almost all of the problems encountered in compiling TOSSIM are due to C linking issues. If you don't know what a linker is (or have never linked a C program), then chances are the rest of this appendix is going to be cryptic and incomprehensible. You're best off starting with learning about linkers, why they are needed, and how you use the gcc/g++ compilers to link code.Generally, when compiling TOSSIM using make micaz sim, one of four things can go wrong:
- You are using Cygwin but the sim compilation option can't figure this out.
- You do not have the needed Python support installed.
- You have Python support installed, but the make system can't find it.
- You have Python support installed, but it turns out to be incompatible with TOSSIM.
- You have a variant of gcc/g++ installed that expects slightly
different compilation options than the normal installation.
1) You are using Cygwin but the sim compilation option can't figure this out
It turns out that the Cygwin and Linux versions of gcc/g++ have different command-line flags and require different options to compile TOSSIM properly. For example, telling the Linux compiler to build a library requires -fPIC while the Cygwin is -fpic. If you're using Cygwin and you see the output look like this:ncc -c -shared -fPIC -o build/micaz/sim.o ...rather than
ncc -c -DUSE_DL_IMPORT -fpic -o build/micaz/sim.o ...then you have encountered this problem. The problem occurs because Cygwin installations do not have a consistent naming scheme, and so it's difficult for the compilation toolchain to always figure out whether it's under Linux or Cygwin.
Symptom: You're running cygwin but you see the -fPIC rather than -fpic option being passed to the compiler.
Solution: Explicitly set the OSTYPE environment variable to be cygwin either in your .bashrc or when you compile. For example, in bash:
$ OSTYPE=cygwin make micaz simor in tcsh
$ setenv OSTYPE cygwin $ make micaz simNote that often this problem occurs in addition to other ones, due to using a nonstandard Cygwin installation. So you might have more problems to track down.
2) You do not have the needed Python support installed
If when you compile you see lots of errors such as "undefined reference to" or "Python.h: No such file or directory" then this might be your problem. It is a subcase of the more general problem of TOSSIM not being able to find needed libraries and files.Compiling Python scripting support requires that you have certain Python development libraries installed. First, check that you have Python installed:
$ python -V Python 2.4.2In the above example, the system has Python 2.4.2. If you see "command not found" then you do not have Python installed. You'll need to track down an RPM and install it. TOSSIM has been tested with Python versions 2.3 and 2.4. You can install other versions, but there's no assurance things will work.
In addition to the Python interpreter itself, you need the libraries and files for Python development. This is essentially a set of header files and shared libraries. If you have the locate command, you can type locate libpython, or if you don't, you can look in /lib, /usr/lib and /usr/local/lib. You're looking for a file with a name such as libpython2.4.so and a file named Python.h. If you can't find these files, then you need to install a python-devel package.
Symptom: Compilation can't find critical files such as the Python interpreter, Python.h or a Python shared library, and searching your filesystem shows that you don't have them.
Solution: Installed the needed files from Python and/or Python development RPMS.
If you have all of the needed files, but are still getting errors such as "undefined reference" or "Python.h: No such file or directory", then you have the next problem: they're on your filesystem, but TOSSIM can't find them.
3) You have Python support installed, but the make system can't find it
You've found libpython and Python.h, but when TOSSIM compiles it says that it can't find one or both of them. If it can't find Python.h then compilation will fail pretty early, as g++ won't be able to compile the Python glue code. If it can't find the python library, then compilation will fail at linking, and you'll see errors along the lines of "undefined reference to __Py...". You need to point the make system at the right place.Open up support/make/sim.extra. If the make system can't find Python.h, then chances are it isn't in one of the standard places (e.g., /usr/include). You need to tell the make system to look in the directory where Python.h is with a -I option. At the top of sim.extra, under the PFLAGS entry, add
CFLAGS += -I/pathwhere /path is the path of the directory where Python.h lives. For example, if it is in /opt/python/include, then add CFLAGS += -I/opt/python/include.
If the make system can't find the python library for linking (causing "undefined reference") error messages, then you need to make sure the make system can find it. The sim.extra file uses two variables to find the library: PYDIR and PYTHON_VERSION. It looks for a file named libpython$(PYTHON_VERSION).so. So if you have Python 2.4 installed, make sure that PYTHON_VERSION is 2.4 (be sure to use no spaces!) and if 2.3, make sure it is 2.3.
Usually the Python library is found in /usr/lib. If it isn't there, then you will need to modify the PLATFORM_LIB_FLAGS variable. The -L flag tells gcc in what directories to look for libraries. So if libpython2.4.so is in /opt/python/lib, then add -L/opt/python/lib to the PLATFORM_LIB_FLAGS. Note that there are three different versions of this variable, depending on what OS you're using. Be sure to modify the correct one (or be paranoid and modify all three).
Symptom: You've verified that you have the needed Python files and libraries, but compilation is still saying that it can't link to them ("undefined reference") or can't find them ("cannot find -lpython2.4").
Solution: Change the sim.extra file to point to the correct directories using -L and -I flags.
4) You have Python support installed, but it turns out to be incompatible with TOSSIM.
Symptom: You see a "This python version requires to use swig with the -classic option" error message.Symptom: You see a long string of compilation errors relating to SWIG and Python, e.g.:
/opt/tinyos-2.1.1/tos/lib/tossim/tossim_wrap.cxx: In function ‘void SWIG_Python_AddErrorMsg(const char*)’: /opt/tinyos-2.1.1/tos/lib/tossim/tossim_wrap.cxx:880: warning: format not a string literal and no format arguments
Solution: Install SWIG and regenerate Python support with the sing-generate script in tos/lib/tossim, or install a different version of Python.
5) You have a variant of gcc/g++ installed that expects slightly different compilation options than the normal installation.
Symptom: g++ complains that it cannot find main() when you are compiling the shared library ("undefined reference to `_WinMain@16'").Solution: There are two possible solutions. The first is to include a dummy main(), as described in this tinyos-help posting. The second is to add the -shared option, as described in this web page.
Hopefully, these solutions worked and you can get back to compiling, If not, then you should email tinyos-help.
ERROR:
make: g++ : command not found > make: *** [ sim-exe] Error 127 Sollution:need to install the g++ packages. sudo apt-get install g++