This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Segfault error using -nostartfiles


I am receiving a segfault error when I run the code listed below. If I
remove the -notstartfiles flag, from the build script,  all work fine. If
the static data member is not part of the STL all works fine. Any ideals?

Build script
=========================================
#!/bin/sh

# Create shared library's object file
g++ -fpic -Wall -g -c sample.cpp

# Create shared library.
g++ -g -shared -nostartfiles -Wl -o libsample.so sample.o

# Compile program file.
g++ -Wall -g main.cpp libsample.so -o main
=========================================


Main.cpp:
=========================================
#include <iostream>
#include <string>
#include "sample.h"
using namespace std;

int main(int argc, char** argv)
   {
     sample::setString("Hello");
     cout << sample::getString() << endl;
   }
=========================================

Sample.h
=========================================
ifndef SAMPLE_H
#define SAMPLE_H 1
#include <string>
using namespace std;

class sample
   {
   public:
      static string& getString();
      static void setString(char* stringIN);
      static string stuff;
};
#endif
=========================================


Sample.cpp
=========================================
#include "sample.h"

string sample::stuff;

string& sample::getString()
   {
      return stuff;
   }

void sample::setString(char* stringIN)
   {
      stuff.assign(stringIN);
   }
=========================================

E-mail: macfar@us.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]