I3ISU_Opgave3

=Connecting to target=

Exercise 2 Testing Connection
In order to connect to the target we have to use the command: code ssh root@10.9.8.2 code root: The username we want to login with 10.9.8.2: The IP we want to connect to

During this we can encounter different errors: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! Solved by entering: code rm -f ~/.ssh/known_hosts code

Exercise 3 Moving a file
We start by making a new file code echo "Hello World" > abc code Then we copy the file with scp code scp abc root@10.9.8.2:/tmp code abc: The file we want to copy root: Login username. If not specified it will be "stud" 10.9.8.2: Connected IP
 * /tmp : Folder to place file

=Building C++ programs for target=

Exercise 1 Cross compiling the program Hello World and running it on target
code arm-angstrom-linux-gnueabi-g++ -o hello.target main.cpp

file hello.target not stripped
 * 1) hello.target: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16,

Copys to and runs on target

code
 * 1) Hello World!

Exercise 2 Using makefiles to build host and target programs
Makefile for target: code SOURCES   = hello.cpp OBJECTS   = ${SOURCES:.cpp=.o} EXECUTABLE = hello.target CC = arm-angstrom-linux-gnueabi-g++ TARGETS = build clean

build: ${OBJECTS} ${CC} -o ${EXECUTABLE} ${OBJECTS}

clean: @rm ${EXECUTABLE} ${OBJECTS}

main.o:   main.cpp ${CC} -c main.cpp

code Makefile for host (shows only section with differences from //makefile for target//): code SOURCES   = hello.cpp OBJECTS   = ${SOURCES:.cpp=.o} EXECUTABLE = hello.host CC = g++ TARGETS = build clean

code Terminal session: code make -f makefile.host build
 * 1) g++ -c main.cpp
 * 2) g++ -o hello.host main.o

make -f makefile.target clean make -f makefile.target build
 * 1) arm-angstrom-linux-gnueabi-g++ -c main.cpp
 * 2) arm-angstrom-linux-gnueabi-g++ -o hello.target main.o

Copys to target and runs on host and target:

Host:
 * 1) Hello World!
 * 2) This is made with a makefile

Target: code
 * 1) Hello World!
 * 2) This is made with a makefile

Exercise 3 Cross compiling with more extended makefiles
Makefile for host: code SOURCES = main.cpp part1.cpp part2.cpp OBJECTS   = ${SOURCES:.cpp=.o} EXECUTABLE = hello.host CC = g++ TARGETS = build clean

build: ${OBJECTS} ${CC} -o ${EXECUTABLE} ${OBJECTS}

clean: @rm ${EXECUTABLE} ${OBJECTS}

main.o: main.cpp ${CC} -c main.cpp

part1.o: part1.cpp ${CC} -c part1.cpp

part2.o: par2.cpp ${CC} -c part2.cpp code makefile for target (Shows only section with differences from //makefile for host//): code SOURCES = main.cpp part1.cpp part2.cpp OBJECTS   = ${SOURCES:.cpp=.o} EXECUTABLE = hello.target CC = arm-angstrom-linux-gnueabi-g++ TARGETS = build clean

code Terminal session for host: code make -f makefile.host build
 * 1) g++ -c main.cpp
 * 2) g++ -o hello.host main.o part1.o part2.o

./hello.host code Terminal session for target: code make -f makefile.target build
 * 1) This is part1
 * 2) This is part2
 * 1) g++ -c main.cpp
 * 2) g++ -o hello.host main.o part1.o part2.o

Transfer file, connect to target and run program:

code
 * 1) This is part1
 * 2) This is part2

Exercise 4 Improving cross compilation handling in makefiles
In this exercise we had to make the makefiles put the files in seperate folders.

makefile.host code format="make" FOLDER=host SOURCES=main.cpp part1.cpp part2.cpp OBJECTS=${FOLDER}/main.o ${FOLDER}/part1.o ${FOLDER}/part2.o EXECUTABLE=${FOLDER}/hello.host CC=g++ TARGETS=build clean

build:   ${OBJECTS} ${CC} -o ${EXECUTABLE} ${OBJECTS}

clean: @rm -f ${OBJECTS} ${EXECUTABLE}

${FOLDER}/main.o:   main.cpp ${CC} -o ${FOLDER}/main.o -c main.cpp

${FOLDER}/part1.o: part1.cpp ${CC} -o ${FOLDER}/part1.o -c part1.cpp

${FOLDER}/part2.o: part2.cpp ${CC} -o ${FOLDER}/part2.o -c part2.cpp code

makefile.target (Shows only section with differences from //makefile for host//): code format="make" FOLDER=target SOURCES=main.cpp part1.cpp part2.cpp OBJECTS=${FOLDER}/main.o ${FOLDER}/part1.o ${FOLDER}/part2.o EXECUTABLE=${FOLDER}/hello.target CC=arm-angstrom-linux-gnueabi-g++ TARGETS=build clean

code

We had a few problems with the object, if we used search and replace. Therefore the objects are "hard coded" and not a modification of the source list.

Exercise 5 Using Eclipse instead of makefiles
To make this exercise compile we made a new build configuration called Target. Under Project properties > C/C++ build > Settings we changed the following for the configuration Target:
 * For "GCC C++ Compiler", change to
 * For "GCC C Compiler", change to
 * For "GCC C++ Linker", change to
 * For "GCC Assembler", change to

After this we tried to build the project, but got an error (could not find compiler). To solve this we specified the compiler path in Project properties > C/C++ build > Environment. We did this by making a new variable named PATH and gave it the following value: /home/stud/setup-scripts/build/tmp-angstrom_2010_x-eglibc/sysroots/i686-linux/usr/bin/armv7a-angstrom-linux-gnueabi:$PATH

We found the path by using the following command: which arm-angstrom-linux-gnueabi-g++

After this the project build without errors and executed on target as it should.