LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Makefiles and include directories (https://www.linuxquestions.org/questions/programming-9/makefiles-and-include-directories-787288/)

ruysch 02-05-2010 02:21 PM

Makefiles and include directories
 
I have a small hobby project which I have been twiddling with under Win32 using VC++, now I wish to port the source code to linux.
How can I point the Makefile to include source code from other folders than the current (and/or subfolder)

I have a small source code framework which is located in:

home/ruysch/framework/cebidae/

while the main application is placed in:

/home/ruysch/app/

theNbomr 02-05-2010 03:55 PM

This is normally done by telling the compiler where to find header files and by telling the linker where to find libraries. The gcc and most/many/some other C compilers use the '-I' (uppercase 'eye') switch to add a specified directory to the "list of places to find include files". Similarly, the linker obeys the '-L' switch to find libraries.
By convention, makefiles use a couple of macros, CFLAGS & LDFLAGS, to specify these commandline switches. The CFLAGS and LDFLAGS macros are expanded on the compiler/linker commandlines, and cause these tools to look in the right places. Also by convnention, CFLAGS & LDFLAGS are defined somewhere near the top of the Makefile, often in a manner similar to this (assuming GNU make):
Code:

CFLAGS += -I /some/directory -I /someother/directory
LDFLAGS += -L /some/private/libdir

You will probably also have to add to the list of libraries to link, which is done in a slightly unintuitive way. If the name of your library is libMyStuff.so, then you would do something like:
Code:

LDFLAGS += -lMyStuff
The linker will understand that it should look for libMyStuff.so

--- rod.

irmin 02-05-2010 03:57 PM

There are many solutions to this problem and I can't tell you which is best for you. It depends how your Makefile(s) is/are designed or whether it is created automatically e.g. using autotools.

I'd suggest the following solution:
Let the Makefiles in the framework directory create a static and/or shared library and then create a symbolic link in your application directory and let it point to your framework directory. Then modify the Makefile for your application to first go down to the framework directory and execute make to update the framework object files and then compile your application. Furthermore simply add the framework library to your libraries you link your app to and add the include path to the framework to the compiler project.

Since Makefiles are very generic and can be used for many tasks (not only for programming) there is no unique solution to the problem. If you telled more details on your Makefile architecture a better solution would be possible.

ruysch 02-06-2010 08:31 AM

Thanks both of you, I managed to a tiny step further. I might return though cause I still havent solved all my issues.

I am using Makefile, written as I move along in my codebase. I really would like not to be dependend on external tools, build systems etc but prefer to do the building by hand so to speak.


All times are GMT -5. The time now is 02:57 AM.