Closed ish-101 closed 7 years ago
What happens when you add -lpthread
to your compilation flags?
Compilation flags are the options that you provide on command line:
arm-linux-gnueabi-g++ -o main -static main.cpp ev3dev.cpp -lpthread
After adding the -lpthread flag, the program compiled :smiley:
But now, it's giving the following error on execution:
terminate called after throwing an instance of '__gnu_cxx::__concurrence_broadcast_error' what(): __gnu_cxx::__concurrence_broadcast_error Aborted
Looks like -lpthread
links to a pthread library that is incompatible with the one installed on ev3dev. I would try to cross-compile using docker, as is described in this tutorial: http://www.ev3dev.org/docs/tutorials/using-docker-to-cross-compile/
I've installed docker and downloaded the image. I've run it at the folder where my files are kept. Now when I compile, it gives me a huge set of errors. By huge, I mean it feels like there is an error at each line of main.cpp and ev3dev.h
I suspect you need to add -std=c++11 to your compile options. If that does not help, please provide your full command line and see least partyof the error log.
Should I run
1) arm-linux-gnueabi-g++ -o main -std=c++11 main.cpp
OR
2) arm-linux-gnueabi-g++ -o main -std=c++11 main.cpp ev3dev.cpp
Second one.
On running the second one, I'm back to the pthread_create error:
/tmp/ccBdGuxv.o: In function 'std::thread::thread<control::terminate_on_key()::{lambda()#1}>(control::terminate_on_key()::{lambda()#1}&&)': main.cpp:(.text+0x16b4): undefined reference to 'pthread_create' /tmp/ccBdGuxv.o: In function 'std::thread::thread<control::panic_if_touched()::{lambda()#1}>(control::panic_if_touched()::{lambda()#1}&&)': main.cpp:(.text+0x1808): undefined reference to 'pthread_create' collect2: error: ld returned 1 exit status
Ok, so now I ran the second one with -lpthread and it compiled. Let's see if it works by connecting the sensors and motors.
Thanks, now everything is working!
When I try to compile a program that uses thread (for example, drive-test demo), it gives the following error:
undefined reference to pthread_create
for each time the function was called.Thought it has no problem in the statement:
#include <thread>
Also, any program that doesn't use thread is working fine.I'm compiling statically using g++-arm-linux-gnueabi compiler on Ubuntu with the following command:
arm-linux-gnueabi-g++ -o main -static main.cpp ev3dev.cpp