一 ubuntu编译32位程序
运行命令:gcc -v
显示:Target: x86_64-linux-gnu
所以,gcc默认生成64位的程序。如果想编出32位的程序,就要加 -m32选项。且需要安装32位依赖库:
$ sudo apt install build-essential module-assistant -y
$ sudo apt install gcc-multilib g++-multilib -y
二 32位兼容库安装
安装32位兼容lib:
sudo apt install lib32ncurses5 lib32z1 -y
三 启用i386架构
启用i386架构
sudo dpkg --add-architecture i386
sudo apt-get update
四 wsl错误
wsl在执行时发生:Exec format error。
1 sudo apt update
2 sudo apt install qemu-user-static -y
3 sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'
每次打开wsl时都需要执行第三句。
五 环境变量常用命令
1 update-alternatives
update-alternatives
命令用于处理Linux系统中软件版本的切换,使其多版本共存。alternatives的管理目录/etc/alternatives
。
alternatives 管理方式:
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 1120 2017 /usr/bin/python -> /etc/alternatives/python
$ ls -l /etc/alternatives/python
lrwxrwxrwx 1 root root 18 1121 2017 /etc/alternatives/python -> /usr/bin/python2.7
python 这个可执行命令实际是一个链接,指向了/etc/alternatives/python
。而这个也是一个链接,指向了/usr/bin/python2.7
,这才是最终的可执行文件。alternatives 实际上是通过软链接的方式对版本进行管理。
2 export
Linux下export
命令用于设置或显示环境变量。在shell中执行程序时,shell会提供一组环境变量。export可新增,修改或删除环境变量,供后续执行的程序使用。export的效果仅限于该次登陆操作。
export -p
:列出当前的环境变量值。
六 开机自启
本节内容来自这里。
Linux下(以RedHat为范本)添加开机开机自动启动脚本有两种方式;本例系统:Linux(CentOS 7.2)。
1 方法一
使用 /etc/rc.d/rc.local,自动启动脚本。
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
1、授予 /etc/rc.d/rc.local 文件执行权限,命令:chmod +x /etc/rc.d/rc.local
;
2、在文件文件底部添加脚本;
3、重启服务器,查看脚本是否启动;
注意:/etc/rc.d/rc.local脚本执行,在/etc/profile之前,若/etc/rc.d/rc.local用到/etc/profile的环境变量,Shell无法执行成功。
2 方法二
1、编辑服务脚本 xxxx(脚本名),增加内容(要在服务脚本中实现POSIX规范中的函数:start() stop()等),命令:vim /etc/init.d/xxxx
。
2、给脚本增加可执行权限,命令:chmod a+x /etc/init.d/xxxx
。
3、注册xxxx服务名,命令:chkconfig --add xxxx
。
注意执行命令:chkconfig --add xxxx
常常会出现
service myservice does not support chkconfig
我们一般在脚本开头加入下面两句就好了
#vim /etc/init.d/xxxx
添加下面两句到 #!/bin/bash 之后。
# chkconfig: 2345 10 90
# description: xxxx ....
其中2345是默认启动级别,级别有0-6共7个级别。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低
配置系统启动时该脚本默认启动,命令:chkconfig xxxx on
;
配置系统启动时该脚本默认关闭,命令:chkconfig xxxx off
;
4、列出当前的服务和他们的配置,命令:chkconfig --list
;
5、重启服务器,查看脚本是否启动。