This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help on -nodefaultlibs


> Hi,
> 
> We are planning to write some drivers that are independent from both OS and
> hardware platforms, since these drivers will be written by many people and will
> be shared by multiple platforms in source level, it is good that if some kind
> of 'generic' code checking can be done at the time these drivers are put in
> place. Specificly, one of the things i would like to check is that these
> drivers can only use data types and functions that are defined in the driver
> code, no OS or platform specific data or functions can be used. I would like to
> run the gcc in SunUnix environment in a way that no library is provided and
> it will complain if not every function is fully defined in the source. So it
> looks like the -nodefaultlibs link option serves what I need, but it gave me
> lots of errors when I tried it. Can any one give me a help on this? Thanks.
> 
> Example:
> 
> a simple program:
> int main()
> {
>   int x;
>   x = 1;
>   return(0);
> }
> 
> compiled:
> gcc -nodefaultlibs -lgcc main.c
>
I assume the answer depends on the glibc version you are using but you need 
more than only libgcc linked in even for the above example as gcc may use
memset, memcpy and a few other functions to initialize things which are in
libc - so you probably need to supplie a -lc as a minimum (see info gcc 
"Options for Linking"). Also if you are trying to link to a libc that is
not the system default then the header files must also fit (in the above
example this may be irrelevant though).

here is an example makefile I use on a glibc-2.2.X system to link with 
glibc-2.0.7 -

hofrat


---Makefile---
all:	hello

#
# Set this to your glibc copy or pass it on the command line
#
ifndef GLIBC_DEVEL
   GLIBC_DEVEL=/usr/src/your_devel_lib
endif

#
# exlicildy list libraries required
#
LIBRARIES = -lc 
GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
GLIBC_CFLAGS+=-nostdinc -I$(GLIBC_DEVEL)/include -I$(GCCINCDIR) -s

#
# set this to fit your target system
#
CFLAGS = -mcpu=i386 \
         -msoft-float \
         $(GLIBC_CFLAGS) 
LDFLAGS+= -nodefaultlibs \
          -L$(GLIBC_DEVEL)/lib \
          -Wl,-rpath-link,$(GLIBC_DEVEL)/lib \
          $(LIBRARIES)

hello:	hello.c

clean:
	rm -f core *.o hello

.c.o:
	$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ -c $<


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]