srjacob
Posts: 39
Joined: Sun Jun 10, 2018 3:21 pm

anyone using code::blocks?

Sun Jun 24, 2018 9:20 pm

I am trying to compile the Aidafruit LED matrix hzeller/rpi-rgb-led-matrix simple example. I keep getting compile errors and since I am a newbe to linux, I am having problems figuring out what has gone wrong.

Can anyone help?

Thanks in advance.

Steve

User avatar
The Traveler
Posts: 360
Joined: Sat Oct 21, 2017 3:48 pm

Re: anyone using code::blocks?

Sun Jun 24, 2018 9:54 pm

It's always helpful if you post the error output you're getting.

Cheers.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

srjacob
Posts: 39
Joined: Sun Jun 10, 2018 3:21 pm

Re: anyone using code::blocks?

Sun Jun 24, 2018 10:03 pm

Fair enough.


-------------- Build: Debug in DRHE (compiler: GNU GCC Compiler)---------------

g++ -L/home/pi/rpi-rgb-led-matrix/lib -o bin/Debug/DRHE obj/Debug/main.o ../rpi-rgb-led-matrix/lib/librgbmatrix.a /home/pi/rpi-rgb-led-matrix/lib/librgbmatrix.a
../rpi-rgb-led-matrix/lib/librgbmatrix.a(thread.o): In function `rgb_matrix::Thread::Start(int, unsigned int)':
/home/pi/rpi-rgb-led-matrix/lib/thread.cc:44: undefined reference to `pthread_create'
/home/pi/rpi-rgb-led-matrix/lib/thread.cc:62: undefined reference to `pthread_setaffinity_np'
../rpi-rgb-led-matrix/lib/librgbmatrix.a(thread.o): In function `rgb_matrix::Thread::WaitStopped()':
/home/pi/rpi-rgb-led-matrix/lib/thread.cc:35: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
4 error(s), 0 warning(s) (0 minute(s), 0 second(s))

User avatar
The Traveler
Posts: 360
Joined: Sat Oct 21, 2017 3:48 pm

Re: anyone using code::blocks?

Sun Jun 24, 2018 11:40 pm

Looks like you're missing -lpthread in your compilation line. A quick look at the sample code shows #include <pthread.h> in the Thread.h header file so it needs compile/link to the pthreads library usually named pthreads.so.

Here's a concise bit explaining the error and how to fix it: https://www.includehelp.com/c-programmi ... linux.aspx (You don't need to add pthread.h as it's already present in your code).

As your using Code::Blocks, you should be able to add -lpthead into the compiler options dialog.

Cheers.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

srjacob
Posts: 39
Joined: Sun Jun 10, 2018 3:21 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 12:13 am

That worked. Thanks

1dot0
Posts: 430
Joined: Mon Nov 28, 2016 12:31 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 8:19 am

The Traveler wrote:
Sun Jun 24, 2018 11:40 pm
Looks like you're missing -lpthread in your compilation line. A quick look at the sample code shows #include <pthread.h> in the Thread.h header file so it
As your using Code::Blocks, you should be able to add -lpthead into the compiler options dialog.

Cheers.
just out of curiousity:
I once read that
-pthread
would be prefered opposite to
-lpthread
because of re-entrance issues - is that still true?

Heater
Posts: 13648
Joined: Tue Jul 17, 2012 3:02 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 11:16 am

Interesting. Where did you read that?

I'd never even heard of -pthread before. -lpthread has never given me any problems.
Memory in C++ is a leaky abstraction .

1dot0
Posts: 430
Joined: Mon Nov 28, 2016 12:31 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 11:30 am

Heater wrote:
Mon Jun 25, 2018 11:16 am
Interesting. Where did you read that?

I'd never even heard of -pthread before. -lpthread has never given me any problems.
I'm not quite sure, IIRC -pthread is about including pthread macros as well. Perhaps it's like written here:
https://stackoverflow.com/questions/232 ... -compiling
and here:
https://groups.google.com/forum/#!topic ... CEpG0EOCCY
-pthread breaks down to:
-D_REENTRANT -lpthread

so it saves you havng to define _REENTRANT when compiling your code.

thats the only diff I am aware of.

jahboater
Posts: 4769
Joined: Wed Feb 04, 2015 6:38 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 11:32 am

Code: Select all

-pthread
   Define additional macros required for using the POSIX threads library. You should use
   this option consistently for both compilation and linking.  This option is supported
   on GNU/Linux targets, most other Unix derivatives, and also on x86 Cygwin and MinGW
   targets.
Edit: sorry 1dot0 for crossed post. This is from the gcc man page.

1dot0
Posts: 430
Joined: Mon Nov 28, 2016 12:31 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 11:36 am

jahboater wrote:
Mon Jun 25, 2018 11:32 am
If thats all it does, then you need both.
Since I once read about -pthread, I am using just that, no additional -lpthread required. That matches with the qoute above:
-pthread breaks down to:
-D_REENTRANT -lpthread

so it saves you havng to define _REENTRANT when compiling your code.

Heater
Posts: 13648
Joined: Tue Jul 17, 2012 3:02 pm

Re: anyone using code::blocks?

Mon Jun 25, 2018 11:52 am

jahboater,

My gcc man page only says:

-pthread
Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.

And clang --help only says:

-pthread Support POSIX threads in generated code

Neither of which make it sound like something urgent.

So, thanks for the heads up on that.

I guess I never had issues by not using -D_REENTRANT because I have always avoided (or tried to) those dangerous thread unsafe functions in the standard library in my threads.
Memory in C++ is a leaky abstraction .

Darshan_H
Posts: 1
Joined: Thu Jul 04, 2019 3:15 am
Contact: Website

Re: anyone using code::blocks?

Thu Jul 04, 2019 4:03 am

hello, in the below this program I have used code block, see it you will game some idea about it.

Code: Select all

#include < iostream >
using namespace std;
class pwr {
double b;
int e;
double val;
public:
pwr(double base, int ex);
double get_pwr() { return val; }
};
pwr::pwr(double base, int ex)
{
b = base;
e = ex;
val = 1;
if(exp==0) return;
for( ; ex>0; ex--) val = val * b;
}
int main()
{
pwr x(4.0, 2), y(2.5, 1), z(5.7, 0);
cout << x.get_pwr() << " ";
cout << y.get_pwr() << " ";
cout << z.get_pwr() << "\n";
return 0;
}

For more details visit: "https://www.interesting321.com/2019/07/ ... n-cpp.html"
for c++ tutorial visit : https://www.interesting321.com/search/label/C-plus-plus

Return to “C/C++”