AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Porting C++ code

Tue Nov 20, 2018 5:23 pm

In general terms - do I need to rebuild my C++ code which runs fine on 3B , compiles without errors on Zero , but won't execute on Zero?

Basically - is there a difference in BCM2837 and BCM2835 as far as C++ code goes ?

Please no references to BCM hardware differences.
I JUST want to know if the C++ code needs to be compiled differently.

ejolson
Posts: 3052
Joined: Tue Mar 18, 2014 11:47 am

Re: Porting C++ code

Tue Nov 20, 2018 6:30 pm

AnneRanch wrote:
Tue Nov 20, 2018 5:23 pm
In general terms - do I need to rebuild my C++ code which runs fine on 3B , compiles without errors on Zero , but won't execute on Zero?

Basically - is there a difference in BCM2837 and BCM2835 as far as C++ code goes ?

Please no references to BCM hardware differences.
I JUST want to know if the C++ code needs to be compiled differently.
Yes. The instruction set is different between the Zero and the 3B. Note that code compiled for the Zero will run on the 3B (just not the other way around), which is why most of the Raspbian userland works on both systems without change.

User avatar
davidcoton
Posts: 3784
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Porting C++ code

Tue Nov 20, 2018 6:34 pm

I'm going to refer to hardware differences, because the alternative is no answer.

The following paragraph does not consider the possibility of 64-bit code on the BCM2837, only differences in the 32-bit modes.

The two processors have different instruction sets. The BCM2837 can run code compiled for the BCM2835, but not the other way round.
So yes, probably your code needs to be recompiled to target the BCM2835. Then it will run on both -- though performance on the BCM2837 will not be as good as the version compiled for that processor.

The other possibility is that your program targets a facility (multicore, 64-bit, others?) available on the BCM2837 but not on the BCM2835, in which case you will have to do more than just recompile.
Signature retired

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Tue Nov 20, 2018 8:25 pm

Thanks for replies.
Been doing some research and pretty much came to similar conclusion.
Now I need to figure out WHERE to get the proper information to configure GCC, so the code will compile correctly.
I think the answer is in - what "ARM" device is BCM2835 - such info seems hard to find.
But it is a start.
Thanks

PS
I am not sure Zero will handle the job, perhaps 3B was better choice to start with.

User avatar
rpdom
Posts: 14447
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Porting C++ code

Tue Nov 20, 2018 9:08 pm

The ARM CPU cores for each of the Pi models are listed here https://en.wikipedia.org/wiki/Raspberry_Pi#Processor

Basically, the Zero and Pi 1 series use an ARMv6, specifically the ARM1176JZF-S CPU. The Pi 3 range (and later Pi 2) use four ARMv8 ARM Cortex-A53.

User avatar
DavidS
Posts: 4213
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting C++ code

Wed Nov 21, 2018 2:33 am

AnneRanch wrote:
Tue Nov 20, 2018 8:25 pm
Thanks for replies.
Been doing some research and pretty much came to similar conclusion.
Now I need to figure out WHERE to get the proper information to configure GCC, so the code will compile correctly.
I think the answer is in - what "ARM" device is BCM2835 - such info seems hard to find.
But it is a start.
Thanks

PS
I am not sure Zero will handle the job, perhaps 3B was better choice to start with.
No need to configure the compiler. If you are running on the RPi 3B to compile just set the -march=armv6 and -mcpu=arm1176jzf-s options in your the compiler flags variable in your makefile (I am not going to assume that it is CCFLAGS, even though that is what most people use).

That will cause it to compile for the ARMv6 CPU in the Raspberry Pi Zero/ZeroW/A/B/B+ systems. Then it should run on any Raspberry Pi without any problem.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

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

Re: Porting C++ code

Wed Nov 21, 2018 10:59 am

Try simply:-

-march=native -mtune=native

for both platforms, assuming you compile on the machine itself.

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Wed Nov 21, 2018 5:05 pm

Update
Reinstalled TCF Agent and now I can run Diagnostic Test on the TCF connection.
No more funky errors either.

Still get no output on TCF Process Terminal - that should be easy to figure out why.








This problem is getting too convoluted .
Here are some details , in no particular order, or particular importance.
The C++ code compiles and works running on 3B.
There is only ONE parameter / configuration - cross compiler "prefix" arm-linux-gnueabihf- identifying hardware (?)

That came from article which installs TCF Agent.
TCF Agent works fine on 3B and it SUPPOSE TO BE platform independent consequently there SHOULD be no need for configuring the C++ for specific processor. The key is "SHOULD"!

Same C++ code compiles , but won't run on Zero.
Been advised to check if I need to reinstall TCF Agent while connected to Zero.
(So much for platform independent theory )
So I am reinstalling TCF on Zero and get TON of errors indicating missing Java .

Questions
Why "missing Java" now when it worked on 3B ? Using SAME IDE.
Since Eclipse , my IDE , is famous in messing with Java versions I am back to square one.
Is ditching Eclipse an option ? I hope not.
Is installing the latest and greatest Eclipse an option - on my PC?
Been there , done that. In short - not impressed with the idea of porting current project to new Eclipse DIFFERENT workspace.
Perhaps the answer is - ditch Zero for time being until I get all this sorted out.
I am not sure Zero can handle my project anyway, but like to see it working via TCF.

Appreciate all the comments, it is very helpful to be able to "bounce off" some ideas. Thanks.
Last edited by AnneRanch on Wed Nov 21, 2018 5:53 pm, edited 1 time in total.

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

Re: Porting C++ code

Wed Nov 21, 2018 5:17 pm

Now I'm confused.

I thought the question was about porting C++.

Now we have Java and Eclipse in the story.

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Wed Nov 21, 2018 7:20 pm

Don't feel alone.
I said it is convoluted.
C++ code is a product of Eclipse IDE
Different Eclipse IDE version uses different Java version
TCF is a "communication framework " allowing C++ code to be cross-compiled ( by GCC - included in Eclipse )
on PC - running Ubuntu and executed on Raspberry Pi - running Rasbpian.
Each item in this chain has to perform and if it does not...
It is necessary to dissect and find out which part is not doing its job.

At this point Eclipse is NOT producing expected result when complied and linked C++ code / application is running via TCF.

Best part - the TCF diagnostic tool is now working.

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

Re: Porting C++ code

Thu Nov 22, 2018 9:26 am

Ah, now I see your problem. Eclipse. That huge, bloated, slow, complex Java beast.

Sorry I can't be of any help, I've been avoiding anything to do with the Eclipse Foundation. Wasted to much of my life fighting with it in the past.

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Thu Nov 22, 2018 2:31 pm

Sorry to disappoint you - it is not Eclipse issue.
After good night sleep I am going to check ONE more part of the "chain".
And yes, Eclipse in a dog, and has been from get go.
IMHO the Eclipse "foundation" has no business trying to be "Swiss army knife" of software development.
Way over their heads...and no QA whatsoever.
But the answer is simple and often given " what do you expect for free?"

Back to the issue.
TCF Agent passes the diagnostic test which DOES NOT HAVE any documentation / description what it actually does.
And most importantly - how to interpret when such diagnostics fails.
The only indication that "something is happening " on the communication channel is when the media is wired - Ethernet. "Data" LED will flash on the RPi 3B RJ45 plug.

When the media is "WiFi", as on both 3B or Zero W, there is no visible feedback about what is going on.

However , even when TCF diagnostic passes - the TFC Agent was build / complied using WHAT processor ?
The "tutorial" installs TCF Agent on Raspberry. No processor specified.
My guess is ARM 6 (?) - so what is Zero BCM 2837 ARM ?
I am going to double check that next.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22715
Joined: Sat Jul 30, 2011 7:41 pm

Re: Porting C++ code

Thu Nov 22, 2018 4:18 pm

AnneRanch wrote:
Thu Nov 22, 2018 2:31 pm
Sorry to disappoint you - it is not Eclipse issue.
After good night sleep I am going to check ONE more part of the "chain".
And yes, Eclipse in a dog, and has been from get go.
IMHO the Eclipse "foundation" has no business trying to be "Swiss army knife" of software development.
Way over their heads...and no QA whatsoever.
But the answer is simple and often given " what do you expect for free?"
Whilst Eclipse isn't very good on the Pi range (not enough memory), on a decent desktop it does a good job. I use it a lot.

However, it's a nightmare to build, and gets a bit slow at times.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Thu Nov 22, 2018 5:45 pm

And that is exactly why I am struggling with crosscompiling C++ code.

User avatar
DavidS
Posts: 4213
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Porting C++ code

Fri Nov 23, 2018 3:00 pm

The Raspberry Pi Zero is a BCM2835, which uses an ARMv6 implementation in the form of an ARM1176JZF-S CPU. Code compiled to run on the ARMv6 of the BCM2835 on the RPi A/B/A+/B+/Zero/ZeroW will run also on the ARMv8 in the BCM2837 of the new 2B/3B/3B+/3A+ as well as on the ARMv7 in the BCM2836 of the first 2B.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Fri Nov 23, 2018 5:07 pm

Thanks , finally getting somewhere.

Here is what lscpu replies with:

[email protected]:~/org.eclipse.tcf.agent/agent/machine $ lscpu
Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
Model: 4
Model name: ARMv7 Processor rev 4 (v7l)
CPU max MHz: 1200.0000
CPU min MHz: 600.0000
BogoMIPS: 38.40
Flags: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
[email protected]:~/org.eclipse.tcf.agent/agent/machine $


Can you refresh my memory and tell me how to verify OS I am running on RPi and how to tell if it is plain B or +B?

The whole issue appears to be on which hardware the TCF was installed - the procedure I followed about a year ago was for arm6.
BUT - that should work on RPi Zero, and it dos not.
I think using / running 3B (ARM7) but telling TCF to install on ARM6 IS THE PROBLEM.
BUT it worked !

So if I am going to use same SD I need to have means to switch to installation under correct hardware.
I better have SD dedicated to each hardware - KISS!

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

Re: Porting C++ code

Fri Nov 23, 2018 8:12 pm

AnneRanch wrote:
Fri Nov 23, 2018 5:07 pm
Can you refresh my memory and tell me how to verify OS I am running on RPi and how to tell if it is plain B or +B?
To get the human readable name for the Pi model:

Code: Select all

cat /proc/device-tree/model; echo
To get the OS details:

Code: Select all

cat /etc/os-release

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22715
Joined: Sat Jul 30, 2011 7:41 pm

Re: Porting C++ code

Fri Nov 23, 2018 9:04 pm

AnneRanch wrote:
Thu Nov 22, 2018 5:45 pm
And that is exactly why I am struggling with crosscompiling C++ code.
Sorry, I meant build Eclips itself from source, not using its own build and project system, which seems to work fine for me.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Sat Nov 24, 2018 2:23 pm

jahboater wrote:
Fri Nov 23, 2018 8:12 pm
AnneRanch wrote:
Fri Nov 23, 2018 5:07 pm
Can you refresh my memory and tell me how to verify OS I am running on RPi and how to tell if it is plain B or +B?
To get the human readable name for the Pi model:

Code: Select all

cat /proc/device-tree/model; echo
To get the OS details:

Code: Select all

cat /etc/os-release
Thanks.
One more - how can I tell if the OS is 32 or 64 bits?
Not if that should make a difference for GCC, I hope.

AnneRanch
Posts: 91
Joined: Fri Oct 19, 2018 1:48 pm

Re: Porting C++ code

Sat Nov 24, 2018 2:33 pm

jamesh wrote:
Fri Nov 23, 2018 9:04 pm
AnneRanch wrote:
Thu Nov 22, 2018 5:45 pm
And that is exactly why I am struggling with crosscompiling C++ code.
Sorry, I meant build Eclipse itself from source, not using its own build and project system, which seems to work fine for me.
I appreciate any comments, but I need to keep some direction in resolving the issue.

I am making assumptions / decisions based of what I have tried so far and I really do not see how just plain IDE could cause this issue.

I am now testing with basic "Hello world", thus I have eliminated ALL of my code

I am also "eliminating" Eclipse as an issue because it works flawlessly on RPi 3B.
But I did had some issues with Eclipse running TCF diagnostic on both 3B and Zero

That was "corrected" be reinstalling TCF. Again on both 3B and Zero.

I am sure I'll find the answer....

athanasios
Posts: 5
Joined: Mon Jun 10, 2019 5:53 pm

Re: Porting C++ code

Tue Jun 11, 2019 1:24 pm

Hello everyone.

I am trying to port a program originally compiled in Windows to the Raspberry Pi 3 model B+, running Raspbian. I understand the basics in Linux and was able to compile and run "Hello world", but have no real experience with C++ or the Raspberry Pi.

The source code I need to compile is naturally a lot more complicated. Its main purpose is to read data packets arriving at the Pi's Ethernet port from a data acquisition board. I am trying to compile this using Geany, and get lot's of errors, see compiler output appended below.

Can someone help me in any way resolve these errors?


In file included from Multiplicity.cpp:5:0:
DetectorParameters.h:43:2: error: ‘CStringA’ does not name a type
CStringA BoatDataIP;
^~~~~~~~
Multiplicity.cpp:290:55: error: expected ‘,’ or ‘...’ before ‘mult_array_in’
void Multiplicity::update_prob_array(unsigned __int64 mult_array_in[], double prob_array_out[], int len)
^~~~~~~~~~~~~
Multiplicity.cpp:290:6: error: prototype for ‘void Multiplicity::update_prob_array(unsigned int)’ does not match any in class ‘Multiplicity’
void Multiplicity::update_prob_array(unsigned __int64 mult_array_in[], double prob_array_out[], int len)
^~~~~~~~~~~~
In file included from Multiplicity.cpp:4:0:
Multiplicity.h:68:7: error: candidate is: void Multiplicity::update_prob_array(long long unsigned int*, double*, int)
void update_prob_array(unsigned long long mult_array_in[], double prob_array_out[], int len);
^~~~~~~~~~~~~~~~~
Multiplicity.cpp: In member function ‘void Multiplicity::display_mult(double)’:
Multiplicity.cpp:419:2: error: ‘CString’ was not declared in this scope
CString str;
^~~~~~~
Multiplicity.cpp:421:10: error: expected ‘;’ before ‘msg’
CString msg=L"Multiplicity Distributions @ Collection Time = ";
^~~
Multiplicity.cpp:424:2: error: ‘str’ was not declared in this scope
str.Format(L"%.1f sec\n\n",time);
^~~
Multiplicity.cpp:425:2: error: ‘msg’ was not declared in this scope
msg += str;
^~~
Multiplicity.cpp:436:3: error: ‘__int64’ was not declared in this scope
__int64 r_plus_a = this->mult_dist_ra;
^~~~~~~
Multiplicity.cpp:437:11: error: expected ‘;’ before ‘a’
__int64 a = this->mult_dist_a;
^
Multiplicity.cpp:439:31: error: ‘r_plus_a’ was not declared in this scope
str.Format(L"%d \t\t%ld",i, r_plus_a);
^~~~~~~~
Multiplicity.cpp:441:27: error: ‘a’ was not declared in this scope
str.Format(L"\t\t%ld\n",a);
^
Multiplicity.cpp:462:23: error: ‘MB_OK’ was not declared in this scope
if(AfxMessageBox(msg,MB_OK|MB_ICONINFORMATION))
^~~~~
Multiplicity.cpp:462:29: error: ‘MB_ICONINFORMATION’ was not declared in this scope
if(AfxMessageBox(msg,MB_OK|MB_ICONINFORMATION))
^~~~~~~~~~~~~~~~~~
Multiplicity.cpp:462:47: error: ‘AfxMessageBox’ was not declared in this scope
if(AfxMessageBox(msg,MB_OK|MB_ICONINFORMATION))
^
Multiplicity.cpp: At global scope:
Multiplicity.cpp:471:61: error: expected ‘,’ or ‘...’ before ‘arr’
int Multiplicity::get_effective_array_size(unsigned __int64 arr[], int max_len)
^~~
Multiplicity.cpp:471:5: error: prototype for ‘int Multiplicity::get_effective_array_size(unsigned int)’ does not match any in class ‘Multiplicity’
int Multiplicity::get_effective_array_size(unsigned __int64 arr[], int max_len)
^~~~~~~~~~~~
In file included from Multiplicity.cpp:4:0:
Multiplicity.h:82:6: error: candidate is: int Multiplicity::get_effective_array_size(long long unsigned int*, int)
int get_effective_array_size(unsigned long long arr[], int max_len);
^~~~~~~~~~~~~~~~~~~~~~~~

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22715
Joined: Sat Jul 30, 2011 7:41 pm

Re: Porting C++ code

Tue Jun 11, 2019 3:53 pm

athanasios wrote:
Tue Jun 11, 2019 1:24 pm
Hello everyone.

I am trying to port a program originally compiled in Windows to the Raspberry Pi 3 model B+, running Raspbian. I understand the basics in Linux and was able to compile and run "Hello world", but have no real experience with C++ or the Raspberry Pi.

The source code I need to compile is naturally a lot more complicated. Its main purpose is to read data packets arriving at the Pi's Ethernet port from a data acquisition board. I am trying to compile this using Geany, and get lot's of errors, see compiler output appended below.

Can someone help me in any way resolve these errors?


In file included from Multiplicity.cpp:5:0:
DetectorParameters.h:43:2: error: ‘CStringA’ does not name a type
CStringA BoatDataIP;
^~~~~~~~
Multiplicity.cpp:290:55: error: expected ‘,’ or ‘...’ before ‘mult_array_in’
void Multiplicity::update_prob_array(unsigned __int64 mult_array_in[], double prob_array_out[], int len)
^~~~~~~~~~~~~
Multiplicity.cpp:290:6: error: prototype for ‘void Multiplicity::update_prob_array(unsigned int)’ does not match any in class ‘Multiplicity’
void Multiplicity::update_prob_array(unsigned __int64 mult_array_in[], double prob_array_out[], int len)
^~~~~~~~~~~~
In file included from Multiplicity.cpp:4:0:
Multiplicity.h:68:7: error: candidate is: void Multiplicity::update_prob_array(long long unsigned int*, double*, int)
void update_prob_array(unsigned long long mult_array_in[], double prob_array_out[], int len);
^~~~~~~~~~~~~~~~~
Multiplicity.cpp: In member function ‘void Multiplicity::display_mult(double)’:
Multiplicity.cpp:419:2: error: ‘CString’ was not declared in this scope
CString str;
^~~~~~~
Multiplicity.cpp:421:10: error: expected ‘;’ before ‘msg’
CString msg=L"Multiplicity Distributions @ Collection Time = ";
^~~
Multiplicity.cpp:424:2: error: ‘str’ was not declared in this scope
str.Format(L"%.1f sec\n\n",time);
^~~
Multiplicity.cpp:425:2: error: ‘msg’ was not declared in this scope
msg += str;
^~~
Multiplicity.cpp:436:3: error: ‘__int64’ was not declared in this scope
__int64 r_plus_a = this->mult_dist_ra;
^~~~~~~
Multiplicity.cpp:437:11: error: expected ‘;’ before ‘a’
__int64 a = this->mult_dist_a;
^
Multiplicity.cpp:439:31: error: ‘r_plus_a’ was not declared in this scope
str.Format(L"%d \t\t%ld",i, r_plus_a);
^~~~~~~~
Multiplicity.cpp:441:27: error: ‘a’ was not declared in this scope
str.Format(L"\t\t%ld\n",a);
^
Multiplicity.cpp:462:23: error: ‘MB_OK’ was not declared in this scope
if(AfxMessageBox(msg,MB_OK|MB_ICONINFORMATION))
^~~~~
Multiplicity.cpp:462:29: error: ‘MB_ICONINFORMATION’ was not declared in this scope
if(AfxMessageBox(msg,MB_OK|MB_ICONINFORMATION))
^~~~~~~~~~~~~~~~~~
Multiplicity.cpp:462:47: error: ‘AfxMessageBox’ was not declared in this scope
if(AfxMessageBox(msg,MB_OK|MB_ICONINFORMATION))
^
Multiplicity.cpp: At global scope:
Multiplicity.cpp:471:61: error: expected ‘,’ or ‘...’ before ‘arr’
int Multiplicity::get_effective_array_size(unsigned __int64 arr[], int max_len)
^~~
Multiplicity.cpp:471:5: error: prototype for ‘int Multiplicity::get_effective_array_size(unsigned int)’ does not match any in class ‘Multiplicity’
int Multiplicity::get_effective_array_size(unsigned __int64 arr[], int max_len)
^~~~~~~~~~~~
In file included from Multiplicity.cpp:4:0:
Multiplicity.h:82:6: error: candidate is: int Multiplicity::get_effective_array_size(long long unsigned int*, int)
int get_effective_array_size(unsigned long long arr[], int max_len);
^~~~~~~~~~~~~~~~~~~~~~~~


Please start a new thread for this - no point in adding to a mostly unrelated thread. Please add in the C/C++ forum.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Return to “C/C++”