LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-09-2006, 05:27 AM   #1
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 547

Rep: Reputation: 38
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!
 
Old 11-09-2006, 06:20 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
Old 11-09-2006, 06:34 AM   #3
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 547

Original Poster
Rep: Reputation: 38
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=.s

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
 
Old 11-09-2006, 07:32 AM   #4
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 547

Original Poster
Rep: Reputation: 38
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.
 
Old 11-09-2006, 09:16 AM   #5
kalleanka
Member
 
Registered: Aug 2003
Location: Mallorca, Spain
Distribution: xubuntu
Posts: 547

Original Poster
Rep: Reputation: 38
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in using both load time linking and runtime linking durgaprasad_j Linux - General 0 08-01-2006 03:49 AM
Faster Linking cyent Programming 1 06-17-2006 10:16 AM
Linking LS to 'L' uveraser Linux - General 2 05-20-2004 10:24 AM
linking own library bobby2k3 Programming 2 10-20-2003 10:36 AM
C++ linking? ugenn Programming 5 05-14-2002 01:33 AM


All times are GMT -5. The time now is 11:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration