Author Topic: Create and compile Contiki project  (Read 17885 times)

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Create and compile Contiki project
« on: August 13, 2014, 07:23:22 pm »
Hello,

I wonder if somebody has succeeded to create and compile a Contiki project using Code::Blocks together with GNU GCC compiler for ARM.
When I tried a simple example from ../example/ subfolder, it was OK.
Then I added functionnality from one of ../apps/ subfolders.

Unfortunately relevant source file from a subfolder wasn't compiled despite it was included into project.

Help, please.

Thanks in advance.

Pavel

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6551
    • My Best Post
Re: Create and compile Contiki project
« Reply #1 on: August 13, 2014, 08:15:55 pm »
Post a Build Log.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Also, it will likely need the Code::Blocks (CB) Project (.cbp) attached to your next post to find the cause.

I am going to Gym right now so will NOT be available to help you till a later time.

Posting links to the Compiler download and the code examples you are Compiling will also help me to help you.

Tim S.
« Last Edit: August 14, 2014, 02:11:10 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #2 on: August 14, 2014, 09:21:37 am »
Hello Tim,

Thanks for feedback.
Here it is:
-------------- Build: Debug in cc2538dk (compiler: GNU GCC Compiler for ARM)---------------

Running command: make.exe -f Makefile
using saved target 'cc2538dk'
  CC        ../../cpu/cc2538/./ieee-addr.c
  AR        contiki-cc2538dk.a
  CC        ../../cpu/cc2538/cc2538.lds
  CC        ../../platform/cc2538dk/./startup-gcc.c
  CC        uIPv6_HOST.c
  LD        uIPv6_HOST.elf
uIPv6_HOST.co: In function `process_thread_button_process':
uIPv6_HOST.c:(.text.process_thread_button_process+0x2a): undefined reference to `servreg_hack_init'
uIPv6_HOST.c:(.text.process_thread_button_process+0x4a): undefined reference to `servreg_hack_lookup'
collect2.exe: error: ld returned 1 exit status
make: *** [uIPv6_HOST.elf] Error 1
../../cpu/cc2538/Makefile.cc2538:70: recipe for target 'uIPv6_HOST.elf' failed
rm uIPv6_HOST.co obj_cc2538dk/startup-gcc.o
Process terminated with status 2 (0 minute(s), 3 second(s))
3 error(s), 0 warning(s) (0 minute(s), 3 second(s))

Nevertheless the function server_hack_init is included in the project (please, see the image in attachment).

Regards

Pavel.

[attachment deleted by admin]

Offline Vuki

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Create and compile Contiki project
« Reply #3 on: August 14, 2014, 12:46:34 pm »
Normally CodeBlocks compiles all files in the project. However, your project is set to run make command instead. CodeBlocks does not have any control on the build process in this case, it simply runs make. Adding file to the project does nothing because Makefile is not updated automatically.
Solution: open Makefile and add the relevant source file to the list of compiled files. Better solution: create a new project (without make), add necessary files and options, etc.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #4 on: August 14, 2014, 01:26:02 pm »
Hello Vuki,

Thanks for feedback.
I've tried your suggestions - created new project, added necessary files and tried to compile.
Other problem appears - header files aren't seen by sources despite they does present.
Here is build output:
||=== Build: Debug in SERVER_HACK (compiler: GNU GCC Compiler for ARM) ===|
..\..\..\core\loader\cle.c|38|fatal error: contiki.h: No such file or directory|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

And here is snapshot of project (image below). As you can state, contiki.h does present in the project.
Where I've been mistaken ?

Another question - original project was organized with virtual folders (in new project I dispensed with this option).
Can this detail be important for success of compilation/building ?

Regards

Pavel



[attachment deleted by admin]

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #5 on: August 14, 2014, 05:44:09 pm »
The header file 'contiki.h' in your screenshot is located in a different folder than the source file 'cle.c'. Usually files included with double quotes ("") are searched in the same folder of which the file includes them so the error is obvious. What you have to do is to enter the correct directories for the header files (or any other types of files if necessary) in the project settings. But be aware that you may end up with other problems if the makefile is a complex one in which case you have to insert all the other settings it contains into CB.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #6 on: August 14, 2014, 07:08:13 pm »
Hello Scarphin,

Thanks for feedback.
Is there some other way to proceed ... i.e. without adding prefixes into header declarations.
The problem is that the hierarchy is quite complex and number of files to process is huge.

The makefile I used for compilation is very simple. Here it's contents:
Code: [Select]
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = my_udp_client

all: $(CONTIKI_PROJECT)

CONTIKI = ../..
include $(CONTIKI)/Makefile.include

What is complex is Makefile.include. Its size is 8k and its syntax is quite complex - instructions, flags, compilations.
It is situated in the root of Contiki installation and obviously allows to circumvent the problem with header prefixes.

What keeps my attention - in initial project whole concerned staff (.c, .h) was added into so-called "virtual" folders (of green color) whereas in my new project I added all staff directly. In this last case the folders are of blue color.

Probably here is the key of enigme ?

Regards

Pavel.



Offline Vuki

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Create and compile Contiki project
« Reply #7 on: August 14, 2014, 07:43:01 pm »
Project properties, Compiler search dirs. Put locations of included headers there (relative paths will do). See INCLUDES options in the Makefile for reference.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #8 on: August 14, 2014, 08:23:19 pm »
Is there some other way to proceed ... i.e. without adding prefixes into header declarations.
My humble advice would be continuing using the makefile with CB and adding your extra files to the makefile.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #9 on: August 15, 2014, 10:55:29 am »
I've created source in the project, that uses functions from files already included in project.
In the makefile I replaced older source par new one.
Apparently everything is Ok and new source should be compiled without problem.
But NOT !!! There is still this annoying error ... undefined reference. Here is build log fragment:
Code: [Select]
my_udp_client.c(.text.process_thread_udp_client_process+0xae) undefined reference to 'uip_ds6_set_addr_iid'
my_udp_client.c(.text.process_thread_udp_client_process+0xb8) undefined reference to 'uip_ds6_addr_add'
my_udp_client.c(.text.process_thread_udp_client_process+0x1b0) undefined reference to 'uip_ds6_if'
..\..\cpu\cc2538\Makefile.cc2538 70 recipe for target 'my_udp_client.elf' failed
=== Build failed: 4 error(s), 12 warning(s) (0 minute(s), 4 second(s)) ===

I checked object subfolder - where *.o and *.d filles are stocked. The object file uip-ds6.o (from where originated functions uip_ds6_set_addr_iid and uip_ds6_addr_add) does present in the object subfolder ...

What could signify these errors ? The builder (make.exe) cannot link these object ?

Cordially

Pavel

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #10 on: August 15, 2014, 03:05:39 pm »
Have you used correct paths for the header files in YOUR source file?

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #11 on: August 15, 2014, 03:34:21 pm »
Here is "header part" of my source:

Code: [Select]
#include "contiki.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "net/uip.h"
#include "net/uip-ds6.h"
#include "net/uip-udp-packet.h"
#include "sys/ctimer.h"

I think that they are correct otherwise there were errors, related to non-identified headers.
But there is no such errors.

Other argument: in another example, that is succesfully built and works, I also use #include "contiki.h".
As you can state, there is no path prefix before contiki.h despite of fact that contiki.h is situated upper in hierarchy than source and project files (also contiki.h isn't in the root directory of disc "C").

Also as I already told, .c file that contains functions (those that provoked built errors) is compiled ... I see corresponding object (.o file).

If my comprehension is correct - compiled file cannot be linked for some reason. Isn't it ?

Cordially

Pavel.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #12 on: August 15, 2014, 08:26:18 pm »
Ok then, did you also insert your 'source.o' file into the linker settings in the makefile?

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #13 on: August 18, 2014, 11:54:55 am »
Hello Scarphin,

There is no any settings, related to ".o" files inside makefile. A propos, here it is:

Code: [Select]
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
CONTIKI_PROJECT = my_udp_client

all: $(CONTIKI_PROJECT)

CONTIKI = ../..
include $(CONTIKI)/Makefile.include

The "obj subfolder" (where all .o files are stocked) contains 293 items.
Among them there is .o file, where there are functions, that cannot be linked (those that provoke "undefined reference" errors).

The question that arises - what is particular in these functions, that they cannot be linked, while others (from other .o files) - YES.

Regards

Pavel.

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #14 on: August 18, 2014, 05:49:03 pm »
As far as I know one must add his/her object '.o' files to the makefile for linkage. You have to consult makefile documentation to be sure.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #15 on: August 19, 2014, 01:46:27 pm »
At the bottom of Makefile there is a line:

CONTIKI = ../..
include $(CONTIKI)/Makefile.include

Here I didn't properly understand what "../.." means - current folder (the folder where is project file) ?
In this case how include $(CONTIKI)/Makefile.include does work - file Makefile.include is situated at the top of Contiki package ?
Nevertheless I'm sure that it does work, so probably "../.." points to the top of Contiki package (that in reality is: C:\Users\Pavel\Documents\Proj_EPFL\contiki-2.7\).
Strange ... it seems that placeholder "../" in windows points to the root directory, i.e. C:, isn't it ?

Anyway here is extract from Makefile.include:

include $(CONTIKI)/core/net/Makefile.uip

And here is contens of C:/Users/Pavel/Documents/Proj_EPFL/contiki-2.7/core/net/Makefile.uip:

Code: [Select]
NET = \
dhcpc.c \
hc.c \
nbr-table.c \
netstack.c \
packetbuf.c \
packetqueue.c \
psock.c \
queuebuf.c \
resolv.c \
sicslowpan.c \
simple-udp.c \
tcpdump.c \
tcpip.c \
uaodv-rt.c \
uaodv.c \
uip-debug.c \
uip-ds6-route.c \
uip-ds6-nbr.c \
uip-ds6.c \
uip-fw-drv.c \
uip-fw.c \
uip-icmp6.c \
uip-nd6.c \
uip-neighbor.c \
uip-over-mesh.c \
uip-packetqueue.c \
uip-split.c \
uip-udp-packet.c \
uip.c \
uip6.c \
uip_arp.c \
uiplib.c

As you can state inside of this list there is file "uip-ds6.c", that contains source code of functions
uip_ds6_set_addr_iid
uip_ds6_addr_add

Call of these functions (in the project source file) result "undefined reference" errors.

Next, I open uip-ds6.c in Code::Blocks and see that all the code is "pale", what probably means that code is ignored by due to #if statement (Am I correct ?).
The most external #if statement is:
#if UIP_CONF_IPV6

Then I go to my source and add the following line (in bold):
#include "contiki.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "net/uip.h"
#define UIP_CONF_IPV6
#include "net/uip-ds6.h"
#include "net/uip-udp-packet.h"
#ifdef WITH_COMPOWER

As you can state it's included before #include "net/uip-ds6.h", so "define" should be accepted inside of uip-ds6.c.

But NOT !!!
After compiling there are still the same errors, also the code inside of uip-ds6.c is "pale".

I become crazy with all this staff ...






Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #16 on: August 19, 2014, 02:10:11 pm »
Yesss !!!
Works !

Here is workflow on problem resolution:

At the top of Makefile there is line:
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"

I opened project-conf.h ... and indeed have found UIP_CONF_IPV6 definition:
/* Don't let contiki-default-conf.h decide if we are an IPv6 build */
#ifndef UIP_CONF_IPV6
#define UIP_CONF_IPV6                        0
#endif

I've replaced '0' by '1' and rebuilt project.
No errors !!!
But curiously the code inside of uip-ds6.c remains "pale". Why ?

Also, can somebody clarify the issue with "../.." ?

Thanks

Pavel

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #17 on: August 19, 2014, 02:21:41 pm »
'../..' means 2 folders up in the path starting from the current folder.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #18 on: August 19, 2014, 02:33:06 pm »
Thanks Scarphin

For 3 levels up: ".../..." and for 4 levels up "..../...." ?

Also, can you explain the issue with "pale" code (although not so critical ... just to clarify the properties of Code::Blocks interface).

Cordially

Pavel

P.S. Here is pale look of source

Offline scarphin

  • Lives here!
  • ****
  • Posts: 644
Re: Create and compile Contiki project
« Reply #19 on: August 19, 2014, 10:28:55 pm »
3 levels: '../../..'
4 levels: '../../../..'
Unfortunately these kinds of questions are not related to CB and not allowed in the forum, please do your own research if you think your question is not related to CB. I have no idea about the grey code, might be some misconfiguration.

Offline Pavel_47

  • Multiple posting newcomer
  • *
  • Posts: 66
Re: Create and compile Contiki project
« Reply #20 on: August 19, 2014, 11:19:35 pm »
Ok, thanks Scarphin.