Tag Archives: The script

The solution of undefined reference to error

Chen Yunwen

 

When compiling programs under Linux, we often encounter “undefined reference to XXX” error,

Here is a summary of some possible reasons and solutions for those in need:

 

Speaking of undefined reference error, let’s first mention the link rules of Linux GCC

 

The search order of links is as follows:

 

    – L to find the path specified by the environment variable library from left to right_ Path, use the ‘:’ partition to find / etc from left to right/ ld.so.conf The specified path order is / lib and / usr / lib (64 bit is / lib64 and / usr / lib64)

Search order of dynamic library calls:

 

The path specified by the – rpath parameter of

    LD is the path specified by the LD script that is written dead in the code_ LIBRARY_ Path / etc/ ld.so.conf The specified paths / lib and / usr / lib (64 bit is / lib64 and / usr / lib64)
are

In general, we use the – L method to specify the search path when linking, and use LD when calling dynamic link library_ LIBRARY_ Path to specify the link path

Another problem to note is that as long as the first one is found, it will be returned, and the later ones will not be found. For example, – L. / a – L. / B – LX has libx in a, libx. A and libx. A in B libx.so In this case, libx. A in. / a will be used instead of following the principle of dynamic library priority, because. / A is found first and there is no dynamic inventory with the same name in

 

 

For dynamic link library, the actual symbol positioning is carried out at run time. When compiling. So, if the library it needs is not associated with it, such as libx.so You need to use uldict, But forget to compile libx.so Add – luldit when compiling libx.so I won’t make a mistake when I’m here, because at this time libx.so It is considered as a library, in which there are some symbols that do not know the specific implementation, which are legal and can be specified at runtime or when compiling other binary programs

If G + + – lpath – LX is used The linker will find that the required uldict symbol table can not be found and report an error. However, if the program is loaded in dlopen mode, the program will run directly in this place and report an error because it is in runtime. Another case is that an external interface has been declared and defined in the dynamic library, but it has forgotten to implement it. At this time, the Similar mistakes can occur

If such an error is reported in the runtime, we should pay attention to whether it is due to the fact that some libraries are not linked or some interfaces are not implemented

 

 

With the above foundation, it is not difficult to see that the reasons for the undefined reference error are as follows:

    no corresponding library (. O /. A /. So) uses the entity defined in the library, but no library (- LXXX) or library path (- lyyy) is specified, which will lead to this error. The order of connecting library parameters is not right. By default, the more basic the library is, the more it should be written later, Whether it is static or dynamic, the version of GCC / LD does not match the compatibility of the version of GCC / LD. Due to the compatibility problems of the large versions of GCC 2 to GCC 3 (in fact, there are some problems in GCC 3.2 to 3.4), when using the low version of the machine on the high version machine, such errors will be caused. This problem is more common in the 32-bit environment, In addition, the 64 bit library is used carelessly in the 32-bit environment, or vice versa. The C / C + + interdependence and the mixed use of linking GCC and G + + compilation results need to ensure that both sides of extern “C” can use the interface. In our 64 bit environment, the GCC linking G + + library also needs to add – lstdc + +, For details, please refer to the description of hybrid compilation in the previous article. The problem of runtime error is basically due to the program using dlopen mode to load. So, but. So does not link all the required libraries. Please refer to the description of hybrid use of static library and dynamic library in the above section

     

Boot / etc/ rc.local What about invalidity? resolvent

Linux boot /etc/rc.local failure problem to provide three ways to solve the boot can not start the rc.local file problem, need friends refer to the following.

/etc/rc.local = /etc/rc.local

1, echo /etc/rc.local>

1, echo /etc/rc.local>; > /etc/profile & & Source /etc/profile

2>eboot

br>

2, reboot

echo /etc/rc.local>
echo /etc/rc.local> > ~/.bash_profile & & The source/etc/profile
Third:
in the/etc/rc3. D increase a startup scripts directory, and then restart the test, the content is as follows:

cat /etc/rc3.d/StartDefautRoute.sh

#! /bin/bash

# [email protected]

route add default gateway 192.168.1.1 dev xenbr0

Some commands cannot be executed in /etc/rc.local
To add a service that automatically runs when the system is started, simply add it to the /etc/rc.local script file. When the command or program is running without a path, for example:

 

#! /bin/bash
Distccd –user nobody –allow 10.10.98.0/24 –log-file=/var/log/distcc.log –verbose –daemon
loadavg-s 10.10.98.20>; /dev/null 2> & 1

Note that the distccd, loadavg commands are stored in /usr/local/bin/
When the system executes these commands, it will report an error and cannot execute properly!
Because the PATH environment variable was not fully initialized when the rc.local script was executed, the directory /usr/local/bin/ was added to the PATH environment variable only after /etc/profile was executed.

Executing commands in /usr/local/bin/directory in /etc/rc.local requires absolute path.

Error installing network file system: Mount error 20 = not a directory

After upgrading to Fedora 9, I found it impossible to mount the Samba Shared file system as before.

when I use the following command:

$mount-t cifs //192.168.1.2/ Samba/MNT/Samba-o Username =test,password=test

mount samba share file gets the following error:

mount error 20 = Not a directory

Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

a Google search revealed that the problem could be due to the cifs file system not being compatible with older samba Shared servers, so either upgrading the samba server program or restricting the cifs would be required to fix the problem. According to the online advice, you can use:

$echo 0 > /proc/fs/cifs/LinuxExtensionsEnabled

modifies the cifs option to disable cifs extensions, and then mount is no problem.

but it was a bit cumbersome to do this every time I restarted, so I changed my system startup script so that I could put these mounts into my fstab and let the system mount automatically every time it was started. The methods are as follows:

modify /etc/init.d/netfs to add a line like the + sign in start as follows:

Case “$1” in the start)

+/sbin/modprobe cifs & amp; & echo 0 > /proc/fs/cifs/LinuxExtensionsEnabled

first execute “/sbin/modprobecifs” to load the cifs module, otherwise the file we want to modify LinuxExtensionsEnabled may not exist yet, and the modification will fail. Since rc*.d/S**netfs at different boot levels are linked to /etc/init.d/netfs, this change takes effect for all boot levels. Of course, if your system is not such a link, it is the same to modify the corresponding file.

there will be no problem installing the samba Shared file system after the restart.

Syntax error near unexpected token `newline’script cannot be executed

Problem description
The run.sh script is executed to report an error with the following message:

/data/app/information-provider
: No such file or directory
: command not found
./run.sh: line 4: syntax error near unexpected token `newline'
'/run.sh: line 4: `case "$1" in  

Problem analysis
Look for the script. The script is fine, so I wonder if the file format is incorrect.
view the file with the following command,

cat -A run.sh

Find that in run.sh, the newline ends with ^M$

server="$( dirname "${BASH_SOURCE[0]}" )" && pwd ^M$
cd $server^M$
^M$
case "$1" in  ^M$
  ^M$
  ...

The solution
Execute the following statement to convert run.sh to a line break of $in the Linux environment

dos2unix run.sh

View the conversion file through Cat-a run.sh as:

server="$( dirname "${BASH_SOURCE[0]}" )" && pwd $
cd $server$
$
case "$1" in  $
  $

Package python3.1 + PyQt4 into exe

There are many programs that package Python as an exe, such as Py2exe, PyInstaller, and so on, but so far none of them support Python 3.1 well, so I’ll introduce CX_freeze 4.2.2 here, which also supports cross-platform running on Windows and Linux.
Cx_freeze download site is http://sourceforge.net/projects/cx-freeze/files/, want to undertake choosing according to install python version. For example, I am using python3.1, so I will download the file cx_Freeze- 4.2.2.2.win32-py3.1.msi. After running the installation package, the program is copied to the Python directory. There are two main places, one is C:/Python31/Scripts and the other is C:/Python31/Lib/site-packages/cx_Freeze
 
In previous versions of cx_Freeze, py was converted to exe through the script Freezepython.py, but in 4.2.2 Freezepython.py is gone and the main work is done by the C:/Python 31/scripts cxfree.bat.
There are two main ways to complete python exe packaging using cx_Freeze:
First, run cxfreeze. Bat directly through:
Go to the CMD command line, enter the C:/Python 31/scripts directory, and run cxfreed.bat-h to see its instructions. We can do an experiment with CX_freeze’s own sample.
Go to C :/ Python 31/scripts/ and run
cxfreeze C:/Python31/Lib/site-packages/cx_Freeze/samples/PyQt4/PyQt4app.py –install-dir=d:/123
Pytqt4app.py is packaged as exe, and the libraries it USES are also evaluated in the d:/123 directory.
 
Second, run setup.py:
In the example provided with CXfreeze C:/ python31/lib /site-packages/cx_Freeze/samples/PyQt4, there is a setup.py file. Open this file and we find that it is:

By running this script, packaging can be done automatically:
For example, if you go into C:/ python31/lib /site-packages/cx_Freeze/samples/PyQt4,
run
setup.py build
After that, a build/exe.win32-3.1 directory will appear under this directory, where you can see the packaged exe file. We want to package our script, copy this setup.py over, and put it in
executables = [Executable(“PyQt4app.py”, base = base)])
Change pyqt4app.py to your own script name.
 
Problems during packaging:
For Chinese support, if there is Chinese in the script and the encoding format is not specified, the packaging process will occur: UnicodeDecodeError: ‘utf8’ codec can ‘t decode bytes in the position of 1602: invalid data this kind of mistake, this blog post on http://www.cnblogs.com/xinzaitian/archive/2010/12/10/1902481.html, the author mentioned Chinese must be deleted.
In fact, Chinese characters can be retained by adding the following at the beginning of the script file:
#! /usr/bin/env python
#coding=utf-8
It is ok
 
Another problem is that if the packaged EXE file is run under “desktop” or other Chinese path, a window will pop up showing “Cannot get zipimporter” instance. So far, no good solution has been found