LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-22-2002, 07:52 PM   #1
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Rep: Reputation: 15
compiling and linking


I'm trying to organize my source files into different subdirectories. My Makefile.am has this line:

myprg_SOURCES = a/a.c b/b.c c/c.c

The problem is that the generated object files are placed in the current directory, but the linker tries to find them in their subdirectories, and therefore fails.

a/a.o
b/b.o
c/c.o

I've looked everywhere but can't find a solution. Any help would be appreciated!
 
Old 12-22-2002, 11:59 PM   #2
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Original Poster
Rep: Reputation: 15
I fixed it!
Had to download the latest autoconf, automake, etc...

The ones that came with RedHat 7.3 were from 1999!!!=?!"?"#¤$



Last edited by boku; 12-23-2002 at 12:00 AM.
 
Old 12-23-2002, 08:04 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I didn't know newer automake/autoconf versions work this way.
Anyways, in previous versions you should have an Makefile.am in each subdir:

In dir a:
myprg_SOURCES = a.c

In dir b:
myprg_SOURCES = b.c

And then have a line:
SUBDIRS = a b c

in the Makefile.am in the root of your source tree.

I have no idea which is the preferred method in the newer version of automake. Anyone?

Last edited by Hko; 12-23-2002 at 08:06 AM.
 
Old 12-23-2002, 05:04 PM   #4
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Original Poster
Rep: Reputation: 15
When I first tried to have a Makefile.am in each subdir it would try to build one executable in each directory.

Looking for a solution to that problem, I found an increasing opinion in favour of a single Makefile.

I think it's somewhat "cleaner" with fewer files. It also seems to build faster, but that may be due to the newer and improved versions of the tools.
 
Old 12-24-2002, 03:09 PM   #5
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Quote:
When I first tried to have a Makefile.am in each subdir it would try to build one executable in each directory.
I vaguely remember you had to get it to build a static library (one with a .a instead of a .so suffix) in each subdirectory, and then link the static libraries into your main executable.

Alex
 
Old 12-25-2002, 09:23 AM   #6
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks! That straightened out a lot of confusions for me as to how Makefiles work.
 
  


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
compiling and linking C programs node047 Linux - General 2 04-20-2005 11:47 AM
Compiling&Linking Error tekin Slackware 4 03-26-2005 08:36 AM
compiling linking help blackzone Programming 1 02-13-2005 10:40 PM
Compiling and linking 64bit code fskmh Slackware 0 01-15-2005 07:04 AM
Compiling GLIBC, and linking it correctly Boudewijn Linux - Newbie 5 11-08-2004 11:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:52 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration