do you compile your program for the version of libstdcpp that is on your gumstix ?

I use everyday [io]fstream, I compile without -static, and it works well.

On 8/1/06, Gillula, Jeremy <Jeremy.Gillula@disney.com> wrote:

Hi everybody,

I've discovered yet another interesting problem (I seem to be encountering these weekly)…this one has to do with the "-static" flag for arm-linux-g++, and how not using it prevents file IO using fstream from operating correctly.  The short version:

* If I try to use the fstream library to read from a file, and don't compile with -static, the file IO doesn't work correctly on the gumstix (and in more complicated programs, causes segfaults)

* If I do use the -static option, everything works fine

The long version:
I have a sample program that's really simple, called file_printer.cc -- all it's supposed to do is read from a file called test.txt, and print its contents to the screen:

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

int main(int argc, char *argv[]) {
        fstream testFile("test.txt");
        string line;

        cout << "Opening file..." << endl;
          if(testFile.is_open()) {
                cout << "File opened succesfully!" << endl;
                while(testFile.good()) {               
                        cout << "Got line: " << line.c_str() << endl;
        cout << "File closed" << endl;
        return 0;

When I compile it using the -static flag, as below…
$host_pc> arm-linux-g++ file_printer.cc -o file_printer -static

The output when I run it on the gumstix is as follows:
$gumstix> ./file_printer
Opening file…
File opened successfully!
Got line: this is line 1
Got line: this is line 2
Got line:
File closed

However, when I compile it without the -static flag, as below…
$host_pc> arm-linux-g++ file_printer.cc -o file_printer

The output when I run it on the gumstix is:
$gumstix> ./file_printer
Opening file…
File opened successfully!
File closed

So clearly, without -static, it is not reading from the file properly...Does anybody know why I need the -static flag?  It would be nice to be able to compile without it, since it makes my executables roughly an order of magnitude larger than they are without it, and I have limited space on the gumstix…  Plus, I'm just sort of curious why it doesn't work without "-static" -- shouldn't arm-linux-g++ use the right standard libraries when it does the compiling and linking?

Thanks in advance!

 - Jeremy

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash

gumstix-users mailing list

Jérôme Multrier
TinyCoach, un projet KaliBee