Hi,
I’m having trouble with a shared lib that I create from
a set of C++ files. The shared lib is created, but everytime
I start a program linked (dynamic) against it, the program
make a segfault (even before executing any code).
Each of the shared lib elements is compiled like this :
$(OBJ_DIR)/Widget.o: Widget.cpp $(H_INCLUDE)/Widget.h
$(CC) $(TARGET) $(CFLAGS) -shared -c Widget.cpp -o $(OBJ_DIR)/Widget.o
where :
CC=QCC
TARGET=-Vgcc_ntox86
CFLAGS=-O3 -Wall -I$(H_INCLUDE) -D_REENTRANT
To create the shared lib, I do :
lib: $(OBJ)
$(CC) $(TARGET) -shared -o $(LIB_DIR)/LibKiPhoton.so $(OBJ)
The program linked against this shared library is done this way :
main: main.cpp $(KILIB)
$(CC) $(TARGET) $(CFLAGS) main.cpp -o main $(LIB) -Bdynamic $(KILIB)
where :
KILIB=/home/jlv/Coding/KiPhoton/lib/LibKiPhoton.so
LIB= -Bdynamic -lphexlib -lph -lphrender -lm
Thanks for any tips/help
Regards,
Jean-Louis
You need to compile with the “-shared” option as well, to create position
independent code.
BTW, to the gurus out there, isn’t there a way that it is being detected
that you use a library where you forgot “-shared” when compiling? Just
crashing isn’t very helpful in debugging
Markus
“Jean-Louis Villecroze” <jlv@kirilla.com> wrote in message
news:9bejoa$gkp$1@inn.qnx.com…
Hi,
I’m having trouble with a shared lib that I create from
a set of C++ files. The shared lib is created, but everytime
I start a program linked (dynamic) against it, the program
make a segfault (even before executing any code).
Each of the shared lib elements is compiled like this :
$(OBJ_DIR)/Widget.o: Widget.cpp $(H_INCLUDE)/Widget.h
$(CC) $(TARGET) $(CFLAGS) -shared -c Widget.cpp -o $(OBJ_DIR)/Widget.o
where :
CC=QCC
TARGET=-Vgcc_ntox86
CFLAGS=-O3 -Wall -I$(H_INCLUDE) -D_REENTRANT
To create the shared lib, I do :
lib: $(OBJ)
$(CC) $(TARGET) -shared -o $(LIB_DIR)/LibKiPhoton.so $(OBJ)
The program linked against this shared library is done this way :
main: main.cpp $(KILIB)
$(CC) $(TARGET) $(CFLAGS) main.cpp -o main $(LIB) -Bdynamic $(KILIB)
where :
KILIB=/home/jlv/Coding/KiPhoton/lib/LibKiPhoton.so
LIB= -Bdynamic -lphexlib -lph -lphrender -lm
Thanks for any tips/help >
Regards,
Jean-Louis
Hi Markus,
In message <9bfq29$93h$1@inn.qnx.com>, “Markus Loffler” wrote:
You need to compile with the “-shared” option as well, to create position
independent code.
To compile in -shared the executable using the library ? Because I already
compiled all the library element in -shared.
Regards,
jean-louis
Sorry I meant
“Jean-Louis Villecroze” <jlv@kirilla.com> wrote in message
news:9bhpou$fhu$1@inn.qnx.com…
Hi Markus,
In message <9bfq29$93h$> 1@inn.qnx.com> >, “Markus Loffler” wrote:
You need to compile with the “-shared” option as well, to create
position
independent code.
To compile in -shared the executable using the library ? Because I already
compiled all the library element in -shared.
Sorry I didn’t see that you are already doing that.
The only thing I can think of right now is to check if really all object
files in $(OBJ) are compiled with -shared.
Have you ever tried building the project with the static lib?
Regards,
jean-louis
To compile in -shared the executable using the library ? Because I already
compiled all the library element in -shared.
Sorry I didn’t see that you are already doing that.
The only thing I can think of right now is to check if really all object
files in $(OBJ) are compiled with -shared.
Have you ever tried building the project with the static lib?
Yes, that what I have to do to continue my project until I found out what
I do wrong with the shared lib, and no problem with the static lib
Regards,
jean-louis
maybe you should try to add -fPIC also when you compile
/MP
“Jean-Louis Villecroze” <jlv@kirilla.com> wrote in message
news:9bejoa$gkp$1@inn.qnx.com…
Hi,
I’m having trouble with a shared lib that I create from
a set of C++ files. The shared lib is created, but everytime
I start a program linked (dynamic) against it, the program
make a segfault (even before executing any code).
Each of the shared lib elements is compiled like this :
$(OBJ_DIR)/Widget.o: Widget.cpp $(H_INCLUDE)/Widget.h
$(CC) $(TARGET) $(CFLAGS) -shared -c Widget.cpp -o $(OBJ_DIR)/Widget.o
where :
CC=QCC
TARGET=-Vgcc_ntox86
CFLAGS=-O3 -Wall -I$(H_INCLUDE) -D_REENTRANT
To create the shared lib, I do :
lib: $(OBJ)
$(CC) $(TARGET) -shared -o $(LIB_DIR)/LibKiPhoton.so $(OBJ)
The program linked against this shared library is done this way :
main: main.cpp $(KILIB)
$(CC) $(TARGET) $(CFLAGS) main.cpp -o main $(LIB) -Bdynamic $(KILIB)
where :
KILIB=/home/jlv/Coding/KiPhoton/lib/LibKiPhoton.so
LIB= -Bdynamic -lphexlib -lph -lphrender -lm
Thanks for any tips/help >
Regards,
Jean-Louis
I don’t know if you saw this - there was a problem with our newsserver.
Colin Burgess <cburgess@qnx.com> wrote:
The first thing to do is to check for non-PIC code in your shared
library. Do this by running objdump -x on your shared library and
looking for relocation section on text segments (eg rel.text)
I can’t see anything wrong about your makefile wrt PIC. Could you
post the address at which it is crashing, plus a ls -l of your libc.
Also, you might want to add -Wl,-soname=LibKiPhoton.so to your
library link line, if you will be debugging this shared library.
Also also, I would link libph etc against your LibKiPhoton.so as well.
Jean-Louis Villecroze <> jlv@kirilla.com> > wrote:
Hi,
I’m having trouble with a shared lib that I create from
a set of C++ files. The shared lib is created, but everytime
I start a program linked (dynamic) against it, the program
make a segfault (even before executing any code).
Each of the shared lib elements is compiled like this :
$(OBJ_DIR)/Widget.o: Widget.cpp $(H_INCLUDE)/Widget.h
$(CC) $(TARGET) $(CFLAGS) -shared -c Widget.cpp -o $(OBJ_DIR)/Widget.o
where :
CC=QCC
TARGET=-Vgcc_ntox86
CFLAGS=-O3 -Wall -I$(H_INCLUDE) -D_REENTRANT
To create the shared lib, I do :
lib: $(OBJ)
$(CC) $(TARGET) -shared -o $(LIB_DIR)/LibKiPhoton.so $(OBJ)
The program linked against this shared library is done this way :
main: main.cpp $(KILIB)
$(CC) $(TARGET) $(CFLAGS) main.cpp -o main $(LIB) -Bdynamic $(KILIB)
where :
KILIB=/home/jlv/Coding/KiPhoton/lib/LibKiPhoton.so
LIB= -Bdynamic -lphexlib -lph -lphrender -lm
Thanks for any tips/help >
Regards,
Jean-Louis
cburgess@qnx.com
–
cburgess@qnx.com
Colin could you take a look at my post (in qnxrtp.os thread “dlopen”).
I don’t know if it is related to this problem (since my code crashes in
dlopen), but this is code that used to work, and stopped working with
released patch ‘A’ I think (doesn’t work on patch ‘B’ either. I have a
test program as an attachment. Could you see if it works on whatever
your using internally ?