cygwin - gcc/ld: undefined reference to unused function -


i'm using gcc 4.3.4 , ld 2.20.51 in cygwin under windows 7. here's simplified version of problem:

  • foo.o contains function foo_bar() calls bar() in bar.o
  • bar.o contains function bar()
  • main.c calls functions in foo.o, foo_bar() not in call chain

if try compile main.c , link foo.o, undefined reference _foo_bar error ld. can see makefile except below, i've tried using flags putting each function in own section , having linker discard unused sections.

compile_cygwin = gcc -iquote$(incdir) compile = $(compile_cygwin) -g -mmd -mp -wall -ffunction-sections -wl,-gc-sections $(define) main_objects = main.o foo.o main.exe : $(main_objects)     $(compile) -o main.exe $(main_objects) 

the function foo_bar() short function provides connection between 2 networking layers in protocol stack. programs don't need it, won't link in other object files related upper layer of stack. it's small function, , seems inappropriate put own .o file.

i don't understand why ld throws error -- nothing calling foo_bar(), there's no need include bar() in final executable. coworker has told me ld not "smart linker", maybe i'm trying isn't possible?

unless linker cyberdyne systems has no way know functions called. knows ones referenced. skynet's linker can't predict run-time decisions made or happen if load module dynamically @ run-time , starts calling various global functions1.

so, if link in module m , references function f, need link whatever module has f.


1. problem related halting problem , has been proven undecidable.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -