2.1.1.3 : The compilation

The compilation is decomposed in 4 steps :

  • Create a build directory in the main directory of our project
  • Go into it
  • Call cmake
  • Call make


So, let's create this build directory :

mkdir build


Then we go into it :

cd build


We call cmake :

cmake ..
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: XXX/build

The .. is to call the parent directory as ../


Finally we call make :

1
2
3
4
5
make
Scanning dependencies of target hadamard_product
[ 50%] Building CXX object CMakeFiles/hadamard_product.dir/main.cpp.o
[100%] Linking CXX executable hadamard_product
[100%] Built target hadamard_product


Now, let's execute our program :

./hadamard_product
Hadamard product
tabResult[0] = 0
*** Error in `./hadamard_product': double free or corruption (!prev): 0x00000000024e3030 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fd7a463f7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7fd7a4647e0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fd7a464b98c]
./hadamard_product(_Z23evaluateHadamardProductm+0x24f)[0x40119f]
./hadamard_product(main+0x2c)[0x400c6c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fd7a45e8830]
./hadamard_product(_start+0x29)[0x400cf9]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 6963418                            XXX/build/hadamard_product
00601000-00602000 r--p 00001000 08:01 6963418                            XXX/build/hadamard_product
00602000-00603000 rw-p 00002000 08:01 6963418                            XXX/build/hadamard_product
024d1000-02503000 rw-p 00000000 00:00 0                                  [heap]
7fd7a0000000-7fd7a0021000 rw-p 00000000 00:00 0 
7fd7a0021000-7fd7a4000000 ---p 00000000 00:00 0 
7fd7a40a9000-7fd7a40bf000 r-xp 00000000 08:01 8651671                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd7a40bf000-7fd7a42be000 ---p 00016000 08:01 8651671                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd7a42be000-7fd7a42bf000 rw-p 00015000 08:01 8651671                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7fd7a42bf000-7fd7a43c7000 r-xp 00000000 08:01 8652856                    /lib/x86_64-linux-gnu/libm-2.23.so
7fd7a43c7000-7fd7a45c6000 ---p 00108000 08:01 8652856                    /lib/x86_64-linux-gnu/libm-2.23.so
7fd7a45c6000-7fd7a45c7000 r--p 00107000 08:01 8652856                    /lib/x86_64-linux-gnu/libm-2.23.so
7fd7a45c7000-7fd7a45c8000 rw-p 00108000 08:01 8652856                    /lib/x86_64-linux-gnu/libm-2.23.so
7fd7a45c8000-7fd7a4787000 r-xp 00000000 08:01 8652890                    /lib/x86_64-linux-gnu/libc-2.23.so
7fd7a4787000-7fd7a4987000 ---p 001bf000 08:01 8652890                    /lib/x86_64-linux-gnu/libc-2.23.so
7fd7a4987000-7fd7a498b000 r--p 001bf000 08:01 8652890                    /lib/x86_64-linux-gnu/libc-2.23.so
7fd7a498b000-7fd7a498d000 rw-p 001c3000 08:01 8652890                    /lib/x86_64-linux-gnu/libc-2.23.so
7fd7a498d000-7fd7a4991000 rw-p 00000000 00:00 0 
7fd7a4991000-7fd7a4b03000 r-xp 00000000 08:01 10356490                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7fd7a4b03000-7fd7a4d03000 ---p 00172000 08:01 10356490                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7fd7a4d03000-7fd7a4d0d000 r--p 00172000 08:01 10356490                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7fd7a4d0d000-7fd7a4d0f000 rw-p 0017c000 08:01 10356490                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7fd7a4d0f000-7fd7a4d13000 rw-p 00000000 00:00 0 
7fd7a4d13000-7fd7a4d39000 r-xp 00000000 08:01 8652926                    /lib/x86_64-linux-gnu/ld-2.23.so
7fd7a4f02000-7fd7a4f07000 rw-p 00000000 00:00 0 
7fd7a4f35000-7fd7a4f38000 rw-p 00000000 00:00 0 
7fd7a4f38000-7fd7a4f39000 r--p 00025000 08:01 8652926                    /lib/x86_64-linux-gnu/ld-2.23.so
7fd7a4f39000-7fd7a4f3a000 rw-p 00026000 08:01 8652926                    /lib/x86_64-linux-gnu/ld-2.23.so
7fd7a4f3a000-7fd7a4f3b000 rw-p 00000000 00:00 0 
7ffc3f094000-7ffc3f0b6000 rw-p 00000000 00:00 0                          [stack]
7ffc3f18e000-7ffc3f190000 r--p 00000000 00:00 0                          [vvar]
7ffc3f190000-7ffc3f192000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Abandon (core dumped)


Oups, we can say that the system highly disagree on this execution.