###### tags: `sysprog2018`
# 2018q3 Homework5 (bits)
contributed by < `goho302jo03` >
## 環境設定
```
$ make check
gcc -O0 -g -Wall -Werror -m32 -lm -o btest bits.c btest.c decl.c tests.c
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/5/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
Makefile:13: recipe for target 'btest' failed
make: *** [btest] Error 1
```
發現還沒有安裝 32-bit 的開發套件,可是在安裝 gcc:i386 時,出現了
```
$ sudo apt install gcc:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
gcc:i386 : Depends: cpp:i386 (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
Depends: gcc-5:i386 (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
```
接著嘗試安裝 cpp:i386
```
$ sudo apt install cpp:i386
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
cpp:i386 : Depends: cpp-5:i386 (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
```
接著嘗試安裝 cpp-5:i386
```
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
dh-php lib32asan2 lib32atomic1 lib32cilkrts5 lib32gcc-5-dev lib32gomp1 lib32itm1 lib32mpx0 lib32quadmath0 lib32ubsan0 libgfortran-5-dev libltdl-dev
libx32asan2 libx32atomic1 libx32cilkrts5 libx32gcc-5-dev libx32gcc1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++6 libx32ubsan0 pkg-php-tools
shtool
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libgmp10:i386 libisl15:i386 libmpc3:i386 libmpfr4:i386
Suggested packages:
gcc-5-locales:i386
The following packages will be REMOVED:
build-essential cpp cpp-5 g++ g++-5 gcc gcc-5 gcc-5-multilib gcc-multilib gfortran gfortran-5 libtool php7.0-dev ubuntu-desktop x11-session-utils
x11-xserver-utils xorg
The following NEW packages will be installed:
cpp-5:i386 libgmp10:i386 libisl15:i386 libmpc3:i386 libmpfr4:i386
0 upgraded, 5 newly installed, 17 to remove and 109 not upgraded.
Need to get 8,830 kB of archives.
After this operation, 72.4 MB disk space will be freed.
Do you want to continue? [Y/n]
```
發現有 17 個套件會被 remove,其中有許多套件感覺 remove 掉會出大事,考量到這不是我個人的主機,於是最後決定使用 docker 來重新建置環境,建置環境過程中參考了 [Installing 32 bit packages on Ubuntu 14.04]('https://akrabat.com/installing-32-bit-packages-on-ubuntu-14-04/') 設定 froeign architectures,最後成功跑出以下結果
```
$ make check
...
ERROR: Test trueThreeFourths(-2147483648[0x80000000]) failed...
...Gives 42[0x2a]. Should be -1610612736[0xa0000000]
ERROR: Test twosComp2SignMag(-2147483647[0x80000001]) failed...
...Gives 42[0x2a]. Should be -1[0xffffffff]
ERROR: Test upperBits(0[0x0]) failed...
...Gives 42[0x2a]. Should be 0[0x0]
Total points: 0/228
```