1

I am trying to move my project to Eclipse (from platformio). I want to pull in some libraries, but I am failing to setup the environment properly to get things compiled.

in my main.cpp I have the following includes:

extern "C"
{
    #include <stdio.h>
    #include "board.h"
    #include "peripherals.h"
    #include "pin_mux.h"
    #include "clock_config.h"
    #include "MIMXRT1021.h"

    #include "FreeRTOS.h"
    #include "task.h" // <== contains the macro BaseType_t xTaskCreate(....)
}

And then the following code

void Test(void *vParameters)
{

}

int main(void) {

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();

    xTaskCreate(
            Test,
            "bla",
            100,
            nullptr,
            1,
            nullptr);

    while(1) {}
    
    return 0 ;
}

This gives the following compile error:

C:\Users\baprins\Documents\MCUXpressoIDE_11.3.1_5262\workspace\iobox\Debug/../source/iobox.cpp:64: undefined reference to `xTaskCreate'

I did add the include paths :

enter image description here

What am I missing?

Botje
  • 26,269
  • 3
  • 31
  • 41
bas
  • 13,550
  • 20
  • 69
  • 146
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Botje Aug 06 '21 at 09:59
  • You need to link your program with the FreeRTOS libraries that provide an implementation of this function. – Botje Aug 06 '21 at 10:00
  • @Botje but I am compiling the library in this project. What else do I need to provide to the compiler other than where the source files are? – bas Aug 06 '21 at 10:01
  • The output of your compilation process should be a kernel for a device, right? That means that it should be self-contained, including the actual binary code that makes up `xTaskCreate`. Your compiler is complaining it doesn't have that code, so it cannot make a fully-functioning output. The fix is to tell the compiler "link with the freeRTOS library code that contains the implementation of `xTaskCreate`. – Botje Aug 06 '21 at 10:08
  • Besides the include paths did you also tell the linker to link files build from those sources? – Bart Aug 06 '21 at 10:08
  • @Bart I am reading statements like this everywhere, but havent found yet *how* to add them. :( – bas Aug 06 '21 at 10:10
  • @bas in the tool settings tab you have to scroll down a bit to find the linker settings (if I am not mistaken from the top of my head). – Bart Aug 06 '21 at 10:14
  • If you look at the [Creating a new RTOS project](https://freertos.org/Creating-a-new-FreeRTOS-project.html) documentation, it states you need to compile several .c files provided by FreeRTOS. Are those files included in your build system? – Botje Aug 06 '21 at 10:24
  • @Botje yes they are. They are all present under [project]/libraries/FreeRTOS. But I don't see any .o file appear in my output folder ([project]/Debug). I just need to understand how I tell Eclipse to compile .c files in my libraries folder. – bas Aug 06 '21 at 10:49
  • It's been a while since I used eclipse CDT, but it can be as simple as right clicking the directory and saying "mark as source directory" or something like that. But of course that goes out the window if you're using an external Makefile-based or CMake-based build system. Time to provide a (link to a) [mre] so people can reproduce your error. – Botje Aug 06 '21 at 10:51

1 Answers1

0

As always... once you know what to do, it's really simple ;-)

Go to

  • project properties
  • C/C+ General
  • Paths and Symbols

In the source location tab, add a location where you want to store your libraries. E.g.

enter image description here

I added a "link" and just typed in the name "libraries". Which felt a bit counter intuitive, maybe it can be done more straight forward. The "add folder" button didn't seem to allow to create a new folder.

Anyway, next step is to simply add all include paths in the includes tab.

enter image description here

I am not sure if / when it's necessary, but I added the paths for all configs, all languages. That seems to work fine.

enter image description here

bas
  • 13,550
  • 20
  • 69
  • 146