Click to See Complete Forum and Search --> : Please, help, LD?


al3x
12-14-2002, 06:55 PM
Hello,

I need advice or link to example with code how to use LD linker when linking program with shared libraries and changing entry point of program.

I wrote simple code with some eg XXXmain, function and wrote simple library with xxxentmain function wich has to call XXXmain, on linking stage I got a error, cannot find entry symbol bla bla bla, defaulting to...

So, I want just to call mymain function from function in library, bypassing standard routine from crt1.o and so on.

Kindly Regards,
Zander

truls
12-15-2002, 10:59 AM
on linking stage I got a error, cannot find entry symbol bla bla bla, defaulting to...

How do you call main() in your library?
Can you please quote the exact error message you are getting?
How do you declare main() in your library?

A little more specifics on the error message, and a little bit of code showing exactly where it fails will make it easier( well, actually possible ) to help you out here.

al3x
12-15-2002, 12:20 PM
Sorry for mess code, I am newbie ;)

Makefile

#
# MAKEFILE
#
CC= gcc
LD= ld
FLAGS= -w -Wall
LDFLAGS=
PROGNAME= test

SRC= test.cpp
LIBSRC= starter.cpp

OBJ= test.o
LIBOBJ= starter.o

all: objs
$(LD) -o $(PROGNAME) -z nodefaultlib -e _entmain $(OBJ) \
-L. -lstarter 2> link.log

objs: $(SRC)
$(CC) -c $(FLAGS) $(SRC) 2> compile.log

lib: libobj
$(CC) -nostartfiles -nostdlib -shared -Wl,-soname,libstarter.so.0 \
-o libstarter.so.0.0 $(LIBOBJ)
/sbin/ldconfig -n .
ln -sf libstarter.so.0 libstarter.so

libobj: $(LIBSRC)
$(CC) -fPIC -g -c -Wall $(LIBSRC)

-------------starter.cpp----------------

int MyMain(void)

void _entmain(void){
MyMain();
}

------------test.cpp---------------------

#include<stdio.h>

int MyMain(void){
printf("Hello World!\n");
return 0;
}

That's all. Main idea, I just want to create lib which will be like crt1.o and other standard startup routines. At this stage I want just to override standard routine and call my MyMain function from library function.

Thanx for any help.