Hi, I'm attempting to create a shared library and application which uses that shared library using the option -nostdlib, i.e. statically link in the system libraries. I have created some link rules by past experiences in this area and locating previous attempts by other users. Here's the output of gmake, my environment, source files, ldd output, and last few lines of strace output. To summarize, the library and application seem to build correctly but then when I attempt to run the application, I encounter a "Segmentation fault" - see strace output. I first created the shared library and application without using -nostdlib option and it ran correctly. Any suggestions, etc. are appreciated - many thanks in advance. Thanks. -Chris cborn@linux:~/workspace/cpptests> gmake cd ./src && gmake all gmake[1]: Entering directory `/home/cborn/workspace/cpptests/src' g++ -o tutil.o -c tutil.cpp -g -I../include g++ -O -v -shared -nostdlib -o libtestsl.so tutil.o -L/usr/lib `g++ --print-file-name=crt1.o` `g++ --print-file-name=crti.o` `g++ --print-file-name=crtbegin.o` -L/usr/lib -Wl,-Bsymbolic -Wl,-Bdynamic -lm -lgcc_eh -lgcc -lc -lgcc_eh -lgcc ` g++ --print-file-name=crtend.o` `g++ --print-file-name=crtn.o` Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.1/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/us r/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux Thread model: posix gcc version 3.3.1 (SuSE Linux) /usr/lib/gcc-lib/i586-suse-linux/3.3.1/collect2 --eh-frame-hdr -m elf_i386 -shared -o libtestsl.so -L/usr/lib -L/usr/lib -L/usr/lib/gcc-lib/i586-suse-linux/3.3.1 -L/usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../../i586-suse-linux/lib -L/usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../.. tutil.o /usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crt1.o /usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crti.o /usr/lib/gcc-lib/i586-suse-linux/3.3.1/crtbegin.o -Bsymbolic -Bdynamic -lm -lgcc_eh -lgcc -lc -lgcc_eh -lgcc /usr/lib/gcc-lib/i586-suse-linux/3.3.1/crtend.o /usr/lib/gcc-lib/i586-suse-linux/3.3.1/../../../crtn.o g++ -o main.o -c main.cpp -g -I../include g++ -o main main.o -nostdlib -Wl,-Bstatic -lstdc++ -g -I../include -L../src -Wl,-Bdynamic -ltestsl -Wl,-Bstatic -lstdc++ -L/usr/lib `g++ --print-file-name=crt1.o` `g++ --print-file-name=crti.o` `g++ --print-file-name=crtbegin.o` -L/usr/lib -Wl,-Bsymbolic -Wl,-Bdynamic -lm -lgcc_eh -lgcc -lc -lgcc_eh -lgcc `g++ --print -file-name=crtend.o` `g++ --print-file-name=crtn.o` gmake[1]: Leaving directory `/home/cborn/workspace/cpptests/src' Env: cborn@linux:~/workspace/cpptests> uname -a Linux linux 2.4.21-144-default #1 Fri Nov 14 00:01:36 UTC 2003 i686 i686 i386 GN U/Linux cborn@linux:~/workspace/cpptests> g++ -v Reading specs from /usr/lib/gcc-lib/i586-suse-linux/3.3.1/specs Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking --enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit i586-suse-linux Thread model: posix gcc version 3.3.1 (SuSE Linux) Source: cborn@linux:~/workspace/cpptests/src> cat main.cpp #include <iostream> using namespace std; #include <tutil.h> int main(int nArgc, const char **ppchArgv) { cout << "About to call api in shared lib" << endl; EchoTest("Call to shared library"); cout << "returned from api in shared lib" << endl; exit(0); } cborn@linux:~/workspace/cpptests/src> cat tutil.cpp #include <iostream> #include <tutil.h> using namespace std; void EchoTest(const string& echo) { tutil testobj(echo); } tutil::tutil(const string& echo) { cout << echo << endl; } cborn@linux:~/workspace/cpptests/src> cat ../include/tutil.h #ifndef __tutil_h_included__ #define __tutil_h_included__ #include <string> using namespace std; extern void EchoTest(const string& echo); class tutil { protected: string str_echo; public: tutil(const string& echo); }; #endif//__tutil_h_included__ cborn@linux:~/workspace/cpptests/src> cborn@linux:~/workspace/cpptests/src> ldd libtestsl.so libm.so.6 => /lib/i686/libm.so.6 (0x40014000) libc.so.6 => /lib/i686/libc.so.6 (0x40037000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000) cborn@linux:~/workspace/cpptests/src> ldd main libtestsl.so => libtestsl.so (0x4001a000) libm.so.6 => /lib/i686/libm.so.6 (0x4002d000) libc.so.6 => /lib/i686/libc.so.6 (0x40050000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) cborn@linux:~/workspace/cpptests/src> strace output: open("/home/db2inst1/sqllib/lib/libm.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) stat64("/home/db2inst1/sqllib/lib", {st_mode=S_IFDIR|0755, st_size=3656, ...}) = 0 open("/etc/ld.so.cache", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=51245, ...}) = 0 old_mmap(NULL, 51245, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40020000 close(3) = 0 open("/lib/i686/libm.so.6", O_RDONLY) = 3 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0 5\0\000"..., 512) = 512 fstat64(3, {st_mode=S_IFREG|0755, st_size=183008, ...}) = 0 old_mmap(NULL, 142672, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x4002d000 old_mmap(0x4004f000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x210 00) = 0x4004f000 close(3) = 0 open("tls/i686/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("tls/i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("tls/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("tls/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("i686/mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("i686/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("mmx/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/db2inst1/sqllib/lib/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory) open("/lib/i686/libc.so.6", O_RDONLY) = 3 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320]\1"..., 512) = 512 fstat64(3, {st_mode=S_IFREG|0755, st_size=1461208, ...}) = 0 old_mmap(NULL, 1256644, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x40050000 old_mmap(0x4017c000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x12 c000) = 0x4017c000 old_mmap(0x40181000, 7364, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONY MOUS, -1, 0) = 0x40181000 close(3) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0 x40183000 mprotect(0x4001a000, 20480, PROT_READ|PROT_WRITE) = 0 mprotect(0x4001a000, 20480, PROT_READ|PROT_EXEC) = 0 munmap(0x40020000, 51245) = 0 --- SIGSEGV (Segmentation fault) @ 0 (0) --- +++ killed by SIGSEGV +++ cborn@linux:~/workspace/cpptests/src>