Segfault error using -nostartfiles
Jeffrey Macfarland
macfar@us.ibm.com
Wed Jan 2 08:03:00 GMT 2002
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
More information about the Libstdc++
mailing list