Eclipse C++ unable to compile, undefined reference to 'xTaskCreate' - c++

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 :
What am I missing?

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.
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.
I am not sure if / when it's necessary, but I added the paths for all configs, all languages. That seems to work fine.

Related

CodeBlocks linker problem when trying to use my library

So I made a library with 2 simple functions and I wanted to add it to my codeblocks project but when I run it I get the following error: undefined reference to info::aritmetica::aduna(double, double).
What I did: I went to build options>linker settings and added the full path to my library (the name of it is info_lib.lib). And I also included the full path in the beginning of the main.cpp file (another question, how do I just use the #include "myfile.h" instead of adding the full path of the header file?)
main.cpp code :
#include <iostream>
#include "A:\Programming\info_lib\info_mai_simplu.h"
using namespace std;
int main()
{
cout<<info::aritmetica::aduna(1,2);
return 0;
}

Compilation error after including jsoncpp

When I try to build test sources I get an error like after this.
stl_tree.h:542:14: error: ‘__node’ does not name a type
::new(__node) _Rb_tree_node<_Val>;
Executor's content.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
int main(int argc, char** argv) {
MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
return CommandLineTestRunner::RunAllTests(argc, argv);
}
My test' s source code starts with below includes.
#include <CppUTest/TestHarness.h>
#include <CppUTest/CommandLineTestRunner.h>
#include <CppUTest/UtestMacros.h>
#include <CppUTestExt/MockSupport.h>
#include <iostream>
#include "common/data_util_astro_cfg.h"
TEST_GROUP(ASTRO_UTIL_TEST) {
void setup() { }
void teardown() { }
};
And the "common/data_util_astro_cfg.h" file has following includes.
#include "../data/data_type_file.h"
#include <json/json.h>
static AstroConfigs toAstroConfigs(std::string content)
My problem is I get compilation error with these includes, when I remove line json.h include everything is fine I can get binary output.
I think the problem is about new operator' s conflict. The solution is offered by Cpputest side and it is located on http://cpputest.github.io/manual.html#memory_leak_detection. But it isn't clear somehow. :(
The question has been already defined on Compilation error after including <map>. It is so similar to mine but the problem has solved with creating new project. In that case I have no option for that. I'm using Yocto project and the project has created with auto generation tools as well.
Can you help me on this? (Thank you for your time.)
Unfortunately, I solved the problem after a while. It seems something wrong with CPPUTest. At the top of the test file, I have several includes. Some of them belong to CPPUTest library, some of them are mine. My includes are following CPPUTest that's why I’m getting an error. If I changed their places, it would be working correctly. It seems meaningless, but it is the correct solution. ”PROBLEM SHOULD BE RESOLVED WITH DEFINE CPPUTEST LIBRARIES AT THE BOTTOM OF YOUR INCLUDE LIST.”

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.

undefined reference to function code blocks

main.cpp
#include <iostream>
#include <string>
using namespace std;
void echo(string);
int main()
{
echo("hello");
cout << "Hello world!" << endl;
return 0;
}
print.cpp
#include <iostream>
#include <string>
void echo(string code){
cout << code;
}
After compiling the code in code blocks 12.11, it gives me that error:
undefined reference to `echo(std::string)
I use windows 7 x64.
I have added the directory; Project>build options > search directories and added the current working directory.
All the files are in one console project in code blocks
I believe you should read up a bit more on namespaces usage. You are missing std in print.cpp.
Generally, while starting to learn cpp or getting a grip of the language you should always try writing full names of the classes along with the namespaces. Eventually with practice and some oversights (like now) you will learn why you really need them. In a nutshell namespaces are great:
When you are writing code over multiple files
Compartmentalize your code into separate blocks.
Also, using namespace std; should be used within cpp files mostly (otherwise headers get mangled up.
Anyways, try changing your code to this:
#include <iostream>
#include <string>
void echo(std::string code){
std::cout << code;
}
Then your results will look like this:
> g++ main.cpp print.cpp -o a.out
> ./a.out
helloHello world!
You should get more than that linker error, since you use string without any namespace in your print.cpp file. And if that source file doesn't compile it can't be linked with, and you will get the linker error you have.
Change to e.g.
void echo(std::string code) { ... }
And you do try to link with the object file created from print.cpp ?
I know this is old, but for anyone looking to solve this issue, the following may be a solution for you. If you have g++ follow c++ 11 under project->build options (check your options anyway) then you must check that box for all files you make in the project for the error to be cleared up. I had that annoying undefined reference thing too but now it is gone!
Try "Project/Properties/Build Targets tab". There you should find "Build target files" field. In that filed find "print.cpp" and click the checkbox (now the compiler will build print.cpp).
Some usefull information on Project management in CB
http://www.codeblocks.org/docs/main_codeblocks_en.html
When dealing with strings in C++ its best to sue std::string and your code seems to be wrong with a changes like using std::cout instead of plain cout another thing you need to be careful is linking your files especially files in different directories you need to tell code blocks were to find this print.cpp by going to build option and go for the search tab directory and point to where print.cpp is other wise the other approach is to just build a project which will have the main.cpp and and then add print.cpp class to current project I hope this will be of some help

PDCurses TUI C++ Win32 console app - Access violation reading location

I have downloaded pdcurses source and was able to successfully include curses.h in my project, linked the pre-compiled library and all good.
After few hours of trying out the library, I saw the tuidemo.c in the demos folder, compiled it into an executable and brilliant! exactly what I needed for my project.
Now the problem is that it's a C code, and I am working on a C++ project in VS c++ 2008.
The files I need are tui.c and tui.h
How can I include that C file in my C++ code? I saw few suggestions here
but the compiler was not too happy with 100's of warnings and errors.
How can I go on including/using that TUI pdcurses includes!?
Thanks
EDIT:
I added extern "C" statement, so my test looks like this now, but I'm getting some other type of error
#include <stdio.h>
#include <stdlib.h>
using namespace std;
extern "C" {
#include <tui.h>
}
void sub0()
{
//do nothing
}
void sub1()
{
//do nothing
}
int main (int argc, char * const argv[]) {
menu MainMenu[] =
{
{ "Asub", sub0, "Go inside first submenu" },
{ "Bsub", sub1, "Go inside second submenu" },
{ "", (FUNC)0, "" } /* always add this as the last item! */
};
startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
return 0;
}
Although it is compiling successfully, it is throwing an Error at runtime, which suggests a bad pointer:
0xC0000005: Access violation reading location 0x021c52f9
at line
startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
Not sure where to go from here.
thanks again.
If I'm not mistaken (and I could easily be), it's due to the difference in calling conventions for C/C++. Try making the callbacks extern "C", and make them call a C++ function. Call it a trampoline :)
Finally got it working. The solution was in the steps below:
First I renamed tui.c to tui.cpp
For the header tui.h, I followed the exact same step of wrapping the code as described here.
then in my project i just included the header without any extern "C" block
#include "tui.h"
Compiled and it worked!