Problem compiling C++ program on Humax

MymsMan

Ad detector
I have successfully compiled a C program on the Humax with gcc but I am running into problems with even a Hello World C++ program.
Code:
#include <iostream>
int main( int argc, char** argv )
{
  std::cout << "hello world" << std::endl;
  return 0;
}

I get
Code:
Humax# gcc hworld.cpp
In file included from hworld.cpp:1:0:
/mnt/hd2/mod/bin/../lib/gcc/mipsel-unknown-linux-uclibc/4.5.2/../../../../include/c++/4.5.2/iostream:39:28: fatal error: bits/c++config.h: No such file or directory
compilation terminated.

Looking at the header-files package file list I see that it contains
Code:
/mod/include/c++/4.5.2/mipsel-linux/bits/c++config.h
and
/mod/include/c++/4.5.2/iostream

From the references on StackOverflow it appears problems with bits/c++config.h are common on gcc with numerous suggested works around and a suggestion that is fixed in gcc 4.6

Has anyone succeeded in compiling c++ on a Humax?
 
It's a pain isn't it? I ended up having to do stuff like this:
Code:
g++ -I /mod/include/c++/4.5.2/mipsel-linux/
 
What's so special about programming in C++? What's wrong with just plain C?

(Not a jibe or a joke, serious question for educational purposes)
 
What's so special about programming in C++? What's wrong with just plain C?

(Not a jibe or a joke, serious question for educational purposes)
I want to make a minor change to the Silence program used by detectads which is already written in C++ so I have no real option
 
What's so special about programming in C++? What's wrong with just plain C?
C is procedural and C++ is object-oriented. The latter means it is much easier to write black-boxes which you can test and debug in isolation and then plug together with other black-boxes, assuming you've got the interface design right between them.
C++ also saves you from (re-)implementing standard things longhand because of its Standard Template Library and frees you from the very tedious resource management necessary in C, which can get very complicated when you come to error handling. In other words, you can focus on the task at hand rather than managing the language. There is of course a learning curve associated with this, but once you've got so far you'll wonder why you didn't do it before. I certainly did.
 
Unfortunately, with my limited and pre-OO programming experience, I understand procedural code and glaze over with OO.
 
It's a pain isn't it? I ended up having to do stuff like this:
Code:
g++ -I /mod/include/c++/4.5.2/mipsel-linux/

Having struggled past misplaced headers and getting a clean compile I now find a more fundamental problem of basic maths function not returning the correct values! :mad:

The original authors of silence chose to use rint() and lrint() for rounding to integers in a number of places but these are returning incorrect values on the humax
Code:
round(0.5)  = 1
rint(0.5)  = 1024
lrint(0.5)  = 2147483647
rint(0.75) = 1024
lrint(0.75) = 2147483647
rint(1.0)  = 1024
lrint(1.0)  = 2147483647

I can change to use round() instead but I shouldn't have to - it makes a nonsense of code portability if basic functions are going to fail without warning
What other horrible gotchas am I likely to encounter :confused: ?
 
Can you provide a complete test case?
I tried compiling some Samba stuff and it just generated the most bizarre errors that I gave up.
I think something in the compiler is fundamentally broken.
I haven't managed to get a cross-compiler hosted on Ubuntu working.
 
Can you provide a complete test case?
I tried compiling some Samba stuff and it just generated the most bizarre errors that I gave up.
I think something in the compiler is fundamentally broken.
I haven't managed to get a cross-compiler hosted on Ubuntu working.
Code:
#include <cstdlib>
#include <cmath>
#include <cerrno>
#include <climits>
#include <cstdio>
#include <iostream>

int main( int argc, char** argv )
{
  std::cout << "hello world" << std::endl;
  printf(" INT_MAX    = %d\n",  INT_MAX);
  printf("round(0.5)  = %d\n", round(0.5));
  printf(" ceil(0.5)  = %d\n",  ceil(0.5));
  printf(" rint(0.5)  = %d\n",  rint(0.5));
  printf("lrint(0.5)  = %d\n", lrint(0.5));
  printf(" rint(0.75) = %d\n",  rint(0.75));
  printf("lrint(0.75) = %d\n", lrint(0.75));
  printf(" rint(1.75) = %d\n",  rint(1.75));
  printf("lrint(1.75) = %d\n", lrint(1.75));
  printf(" rint(1.0)  = %d\n",  rint(1.0));
  printf("lrint(1.0)  = %d\n", lrint(1.0));
  std::cout << "bye world" << std::endl;
  return 0;
}
compiled using
Code:
g++ -o hworld -I /mod/include/c++/4.5.2/mipsel-linux/ hworld.cpp

The 'real' code I want to alter is silence.cpp at https://www.mythtv.org/wiki/Commercial_detection_with_silences
Obviously the code can be be compiled for Humax since the program is in the detectads package but unfortunately njm didn't include a source file, and is no longer active on the forums or via conversations.
 
You need to get your format specifiers correct first of all:
Code:
  printf("round(0.5)  = %f\n", round(0.5));
  printf(" ceil(0.5)  = %f\n",  ceil(0.5));
  printf(" rint(0.5)  = %f\n",  rint(0.5));
  printf("lrint(0.5)  = %ld\n", lrint(0.5));
  printf(" rint(0.75) = %f\n",  rint(0.75));
  printf("lrint(0.75) = %ld\n", lrint(0.75));
  printf(" rint(1.75) = %f\n",  rint(1.75));
  printf("lrint(1.75) = %ld\n", lrint(1.75));
  printf(" rint(1.0)  = %f\n",  rint(1.0));
  printf("lrint(1.0)  = %ld\n", lrint(1.0));
but it still doesn't work at all from the first lrint() and subsequently.
 
I don't know what to try next, I don't have any other linux systems to attempt cross compiling - not that I would know where to start, the wiki is silent on the subject :(
 
No I don't know either. Those who do seem not to want anyone else to. I think the only option at this point is give up, sadly.
 
With prpr's modifications to the format specifiers, I was able to compile and run this on the humax itself without doing anything special:

MymsMan - make sure you're using g++ rather than gcc.

Code:
humax# g++ hworld.cpp
humax# ./hworld
hello world
INT_MAX  = 2147483647
round(0.5)  = 1.000000
ceil(0.5)  = 1.000000
rint(0.5)  = 0.000000
lrint(0.5)  = 2
rint(0.75) = 1.000000
lrint(0.75) = 1
rint(1.75) = 2.000000
lrint(1.75) = 2
rint(1.0)  = 1.000000
lrint(1.0)  = 1
bye world

Same results when built using the cross compiler that Humax provide on their open source site.

Code:
humax-dev# (27) mipsel-linux-g++ -o hworld hworld.cpp
humax-dev# (28) scp hworld humax:/mod
hworld  100%  10KB  10.2KB/s  00:00
humax-dev# (29) ssh humax /mod/hworld
hello world
INT_MAX  = 2147483647
round(0.5)  = 1.000000
ceil(0.5)  = 1.000000
rint(0.5)  = 0.000000
lrint(0.5)  = 2
rint(0.75) = 1.000000
lrint(0.75) = 1
rint(1.75) = 2.000000
lrint(1.75) = 2
rint(1.0)  = 1.000000
lrint(1.0)  = 1
bye world

When I was playing around with building silence.cpp I think I did end up using round() instead though but I don't remember the exact details - lrint() didn't seem reliable.

Those who do seem not to want anyone else to.
What makes you say that? I don't recall ever having being asked. Humax provide the cross compiler on their downloads site. All you have to do for basic compilation is unpack it into /opt and then run it.
 
I am definitely using g++ rather than gcc, although I did make that error in my initial post, I soon discovered it doesn't give a clean compile with gcc.

The fact that prpr was able to reproduce the problem after fixing my flawed test case (sorry) also indicates that there is something more than simple senile user error but compiler errors, in my experience, tend to be a lot more subtle than inability to round numbers so it is more likely to be something in our environment that differs from yours.

By cross compiler I assume you mean http://www.humaxdigital.com/uk/opensource.php crosstools_hf-linux-2.6.18.0_gcc-...
but I am not sure that I can do anything useful with that on a Windows 8.1 box! My DIL has my old computer that had a version of Ubuntu working in Virtual box and it seems like a lot of work to reinstall all of that. :)

I will try reinstalling the gcc package and seem if that makes a difference.
 
With prpr's modifications to the format specifiers, I was able to compile and run this on the humax itself without doing anything special
Here's what I get:
Code:
humax# g++ hworld.cpp
In file included from hworld.cpp:1:0:
/mnt/hd2/mod/bin/../lib/gcc/mipsel-unknown-linux-uclibc/4.5.2/../../../../include/c++/4.5.2/cstdlib:43:28: fatal error: bits/c++config.h: No such file or directory
compilation terminated.
humax# g++ -I /mod/include/c++/4.5.2/mipsel-linux/ -o hworld hworld.cpp
humax# ./hworld
hello world
 INT_MAX  = 2147483647
round(0.5)  = 1.000000
 ceil(0.5)  = 1.000000
 rint(0.5)  = 0.000000
lrint(0.5)  = 2147483647
 rint(0.75) = 0.750000
lrint(0.75) = 2147483647
 rint(1.75) = 1.750000
lrint(1.75) = 2147483647
 rint(1.0)  = 1.000000
lrint(1.0)  = 2147483647
bye world
So, what is different about your box compared to ours? Where do we start?
 
I am not sure that I can do anything useful with that on a Windows 8.1 box! My DIL has my old computer that had a version of Ubuntu working in Virtual box and it seems like a lot of work to reinstall all of that.
It's not that hard. I use VBox on Mint and have several server VMs - Ubuntu 12.04LTS is the least annoying of the recent Ubuntus IME. They run quite happily in less than 200MB of memory.
 
So, what is different about your box compared to ours? Where do we start?
It's my development box so I may have done something to it that I don't remember. Just compared it to my stock HD box though and see that I have tweaked the include files at some point. Try updating the header-files package.
 
The old adage applies: Test what you ship and ship what you test.
Now compiles without needing the -I parameter, but it generates the same executable which generates the same erroneous results.
8782 bytes here (tried on 2 boxes with identical results).
 
ditto for me,

I wonder if perhaps you have different versions of the libraries on your development system - in particular the floating point libraries libmpc and libmpfr
 
I shall have another look tonight. As you can probably imagine, my development system contains a lot of things I never intend to ship! I build and test packages like webif (well, anything in the repository) from a second clean HDR.
 
Back
Top