Author Topic: Create and compile Contiki project  (Read 32780 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: 7582
    • 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 64 bit.
--
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
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
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
#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
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.