LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   linking? (https://www.linuxquestions.org/questions/programming-9/linking-500011/)

kalleanka 11-09-2006 05:27 AM

linking?
 
Hi,

now im realy confused. I tried to take away the header-declaration like this /* #include "myheader.h" */ to find all the calls to this file by running make. I do not get a linking error even if I run make clean that delete all objects and the exe. Seams like its some memory for the linker.

Any idees!

ta0kira 11-09-2006 06:20 AM

Rather than commenting out the #include, go into the header and comment out the entire header. This will cause compiler errors everywhere something that was declared in the .h is used. Commenting out the #include would only work on that particular source or header, whereas manipulating the actual originating document will take care of everything that #include's it. Linker errors should only be caused by .c/pp files unless you are using templates.
ta0kira

kalleanka 11-09-2006 06:34 AM

Quote:

Originally Posted by ta0kira
Rather than commenting out the #include, go into the header and comment out the entire header. This will cause compiler errors everywhere something that was declared in the .h is used. Commenting out the #include would only work on that particular source or header, whereas manipulating the actual originating document will take care of everything that #include's it. Linker errors should only be caused by .c/pp files unless you are using templates.
ta0kira

Thanks I will try that method.


I made a little program to test this and it works the same way. If I comment out the include it still works. This must generate a lot of bugs since one migth "forget" some heders and the when someone else tries to compile the source they should get errors. But offcourse Im not shore about this. Maybe its the makefile thats the problem.

the main.c file:
/*#include "a.h"*/
int main(int argc, char *argv[])
{
printf("a");
afunc();
printf("c");
return -1;
}

the a.c file:
void afunc()
{
printf("b");
}

the a.h file:
void afunc();

and my makefile (this one is an overkill but I wanted to test this one since I use it for my application)
CC = gcc
CFLAGS = -O2 -g -O2 -ansi -I/usr/X11R6/include -I/usr/X11R6/include -I/usr/include/freetype2 -I/usr/include/freetype2/freetype2 -I/usr/include/freetype2/freetype2/config -I/usr/X11R6/include `pkg-config gtk+-2.0 --cflags`
LDFLAGS = -L/usr/X11R6/lib -lX11 -lpng -lXpm -lXinerama -L/usr/X11R6/lib -lXft -lX11 -L/usr/lib -lfreetype -lfontconfig -L/usr/X11R6/lib -lXrender -lXext `pkg-config gtk+-2.0 --libs`
VERSION = 1.4
BINDIR = /usr/local/bin

GTK = `pkg-config gtk+-2.0 --cflags --libs`
VPATH=.:os

OBJECTS = a.o main.o

EXE = aprog

.SUFFIXES: .o .h .c

all: $(EXE)

install: all
strip $(EXE)
install -d $(BINDIR)
install $(EXE) $(BINDIR)/$(EXE)

depend:
makedepend -Ym *.c

$(EXE): $(OBJECTS)
$(CC) -o $(EXE) $(OBJECTS) $(LDFLAGS)

help.o: help.c
$(CC) -c $(CFLAGS) -DVERSION=\"$(VERSION)\" help.c

.c.o: $<
$(CC) -c $(CFLAGS) $<

clean:
rm -f $(OBJECTS) $(EXE) core

kalleanka 11-09-2006 07:32 AM

this is a joke. I get no linking error even if I commenting out the whole a.h file like this /* void afunc(); */

I must be a flag in my makefile thets fixing it.

kalleanka 11-09-2006 09:16 AM

Ok I solved it. If I do not run make depend the compiler finds the object directly and no check is done.

I should of chosen more programing courses at university 20 years ago.


All times are GMT -5. The time now is 03:25 AM.