help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:using 'g++ -shared' causes Segmentation fault


From: Vipin Dravid
Subject: Re:using 'g++ -shared' causes Segmentation fault
Date: Wed, 21 Jun 2006 22:18:37 +0530


I *need* to use shared libs (SDL & openGl libs) and I guess it's
-shared switch which set that 'linking option'. Every time I use it
(-shared) ANY program I'm trying to run gives 'Segmentation fault'...


you may need to use shared libs, but surely not _execute_ them. you
will get undefined behaviour  on most platforms if you try to execute
a shared library. AFAIK, for shared lib compiled with "-shared", the
linker defines a bogus entry point and hence execve() results in a
segmentation fault.

You'd have a problem, if you are getting segmentation fault for the
executable which link your shared libraries. Is that the case ?

On 21 Jun 2006 06:50:49 -0700, Mateusz Krzeszowiec
<Mateusz.Krzeszowiec@gmail.com> wrote:

Paul Pluzhnikov wrote:
> "facedancer" <Mateusz.Krzeszowiec@gmail.com> writes:
>
> > I'm trying to learn c++ for Linux and I've got a big problem.
>
> Actually, you don't have a problem ...

Actually, I have a problem :)

I *need* to use shared libs (SDL & openGl libs) and I guess it's
-shared switch which set that 'linking option'. Every time I use it
(-shared) ANY program I'm trying to run gives 'Segmentation fault'...

Yours
poor noob :)

>
> > When I
> > try to link shared libraries to my program it always outputs
> > 'Segmentation fault' when I try to run it.
>
> You are trying to *run* a library, but libraries aren't "runnable"
> on any OS I know of [1].
>
> > Of course I was trying to
> > write something a bit more complicated ;) but after looking for a bug I
> > removed all code and realized that the bug is not caused my my mistake.
>
> Yes, it is. Your mistake is trying to run something that isn't
> intended to run.
>
> > g++ -c -otestSDL.o testSDLa.cpp
> > g++ -shared -otestSDLa testSDLa.o
> > ./testSDLa
> > output: Segmentation fault
>
> Don't do that ... Do this instead:
>
> > g++ -otestSDL.o testSDLa.cpp
> g++ -o testSDLa testSDL.o        # looks like you missed a step
> > ./testSDLa
> > output: ok
>
> Cheers,
>
> [1] Actually, on Linux 2 special libraries are runnable:
> ld-linux.so.2 and libc.so.6. This is achieved via special assembly
> magic, which is too advanced for a beginner to understand :)
> --
> In order to understand recursion you must first understand recursion.
> Remove /-nsp/ for email.

_______________________________________________
help-gplusplus mailing list
help-gplusplus@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gplusplus



--
Regards,
V i p i n

Life is what happens to you while you are busy making other plans.
- John Lenon


--
Regards,
V i p i n

Life is what happens to you while you are busy making other plans.
- John Lenon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]