ISU E3 - Connecting to target and Building Cplusplus programs for target


ISU Exercise 3

Connect to the target

Exercise 1 - Connect to target




If you cannot connect to target try using

      sudo ifdown usb0

Followed by

      sudo ifup usb0 



Exercise 2 Test connection



We were warned about a “MAN-IN-THE-MIDDLE-ATTACK" then we ran the command:

ssh-keygen -R 10.9.8.2. Then establish the connection again.





Exercise 3 Move a file


Create a file using touch 
 Move the file abc to target




Exercise 4 – Create shell scripts for ssh and scp (optional)

The shellscripts conn2tgt.sh and cp2tgt.sh is made very easily. 




Remember to give them executable permission by
    chmod +x <filename>

If we copy these files to the folder /usr/bin they will be executable by direct invoke, meaning we can call them no matter what dir we’re currently standing in.

A smarter way however is to make a soft link to the original file.
Use:

ln –s <source-file> </usr/bin/<filename>

(or cp –s <source-file> </usr/bin/<filename>)

ln will make a link, -s will make it a soft link.


Notice that the shellscripts are located in Documents/Stefan/shellscripts but is invoked from location /Documents and without the ending .sh 





Building C++ programs for target


Exercise 1 Cross compiling the program Hello World and running it on target

Hello.cpp is a copy from a previous lab challenge. Direct invocation to compile hello.cpp for target.



Move hello.target to target. 


And execute it. 




Exercise 2 Using makefiles to build host and target programs 

Hello.cpp and makefile is a copy from a previous challenge. The makefile.target is a modified version of makefile.

makefile.target 
 Compile makefile and makefile.target.

Execution 






Exercise 3 Cross compiling with more extended makefiles 

main.cpp, the two parts and makefile is a copy from a previous challenge. The makefile.target is a modified version of makefile.

makefile: 


makefile.target 


Compile makefile and makefile.target

BEWARE THAT THE *.o FILES COMPILED BY THE TARGET COMPILER CAN AND WILL BE USED TO LINK AN EXECUTABLE FOR THE HOST (and vice versa).. THIS WILL NOT WORK! ..
Since if we've compiled for the host first and tries to compile for the target right after the linker sees that there's no need to update the .o files, and therefor tries to link them, but then it notices that the object-files are of the wrong type (since they were made for host and not target).
Cleaning or overwriting is not efficient, but done for now.

FIX:

    make clean
before each make* call!!


Compile parts and execution on host. 


Compile parts.target and execution on target





Exercise 4 Improving cross compilation handling in makefiles 

Rewrite makefile and makefile.target so that make places the executable(& objects) for host in the sub-directory host/ and the executable(& objects) for target in the subdirectory target/. Also make sure that make clean and make -f makefile.target clean will not remove the opposite executable(& objects) - in other words, make clean must not remove the target executable(& objects), and make -f makefile.target clean must not remove the host executable(& objects).



We start by creating a new variable DIR, which is used as the destination for the files that we compile.

The variable OBJECTS has also changed a bit. The % sign indicates a pattern:
    %.cpp: $ {DIR}% .o
means that for all files that ends in .cpp should have an object file in the subfolder aswell.


    $ {DIR}% .o: %.cp
Here we find all .o files in a particular directory and compile them. $ @ takes target and $ < takes the .o files and compiles them. 

Makefile: 




Makefile.target 




Exercise 5 Merging makefile and makefile.target (Optional) 




The first line checks if the variable ARCH equals "target". If so it will make the dir and compiler accordingly, otherwise it will assume that it should compile to target.

1 kommentar:

  1. For this ecxercise, understanding the differences between compiling for target and host was important. Also, including the differences in the makefiles was important. All this has been accomplished.

    The solution of excercise 4 is also very elegant.
    Nice job!

    SvarSlet