LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   compiling and linking (https://www.linuxquestions.org/questions/programming-9/compiling-and-linking-39154/)

boku 12-22-2002 07:52 PM

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!

boku 12-22-2002 11:59 PM

I fixed it!
Had to download the latest autoconf, automake, etc...

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



Hko 12-23-2002 08:04 AM

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?

boku 12-23-2002 05:04 PM

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.

llama_meme 12-24-2002 03:09 PM

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

boku 12-25-2002 09:23 AM

Thanks! That straightened out a lot of confusions for me as to how Makefiles work.


All times are GMT -5. The time now is 10:11 AM.