This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Segfault error using -nostartfiles
- From: "Jeffrey Macfarland" <macfar at us dot ibm dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Wed, 2 Jan 2002 10:45:06 -0500
- Subject: 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