LinuxQuestions.org
Review your favorite Linux distribution.
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 02-05-2010, 02:21 PM   #1
ruysch
LQ Newbie
 
Registered: Feb 2010
Posts: 4

Rep: Reputation: 0
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/
 
Old 02-05-2010, 03:55 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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.

Last edited by theNbomr; 02-05-2010 at 03:57 PM.
 
Old 02-05-2010, 03:57 PM   #3
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
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.
 
Old 02-06-2010, 08:31 AM   #4
ruysch
LQ Newbie
 
Registered: Feb 2010
Posts: 4

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


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
How to include files from other directories in a program? kirit.makwana Programming 2 05-20-2009 01:26 PM
changing include directories - /usr/local/include quep_fly Linux - Newbie 6 08-12-2007 04:36 PM
Setting permissions that include sub-directories AlcoholicDoc Linux - Newbie 2 12-19-2005 10:33 AM
How to include library directories? davee Programming 7 04-05-2004 05:41 AM
Where to find/How to change .h include directories for g++ sfcesario Linux - Software 1 01-31-2004 10:12 AM


All times are GMT -5. The time now is 12:09 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