Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How do I add an include dir for C programs?

How do I add an include dir for C programs?
Thread Tools
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Aug 8, 2004, 03:09 PM
 
I'd like to include the readline library which is located in my '/sw/include/' folder. When I try to compile this program that uses it, it gives me errors because it cannot find <readline/readline.h>. How do I fix this?
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Aug 8, 2004, 03:40 PM
 
You don't say how you're compiling it, but generally for autotools based projects you need to add "-I /sw/include" to the CFLAGS (and "-L /sw/lib" to the LDFLAGS).
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Aug 8, 2004, 06:34 PM
 
Originally posted by Angus_D:
You don't say how you're compiling it, but generally for autotools based projects you need to add "-I /sw/include" to the CFLAGS (and "-L /sw/lib" to the LDFLAGS).
I'm using 'cc' for to compile it. Using 'cc -I /sw/include -L /sw/lib fileman.c' gives me the following errors:
Code:
fileman.c: In function `dupstr': fileman.c:61: warning: passing arg 1 of `strlen' makes pointer from integer without a cast fileman.c:62: warning: passing arg 2 of `strcpy' makes pointer from integer without a cast fileman.c: In function `fileman_completion': fileman.c:215: warning: assignment makes pointer from integer without a cast ld: -L: directory name missing
I didn't write the program, but I'd assume it's supposed to work since it came from the readline info page. As you can see, at the end it's giving me an error relating to the -L option. Is the command simply wrong? Or is this a source problem?
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 8, 2004, 07:12 PM
 
I don't think there's supposed to be a space between the flags and their arguments (i.e. it should be -L/path/to/directory).

EDIT: Okay, apparently my memory fails me.
(Last edited by Chuckit; Aug 8, 2004 at 07:35 PM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Aug 8, 2004, 07:27 PM
 
Originally posted by Chuckit:
I don't think there's supposed to be a space between the flags and their arguments (i.e. it should be -L/path/to/directory).
That gives me even more errors:
Code:
fileman.c: In function `dupstr': fileman.c:61: warning: passing arg 1 of `strlen' makes pointer from integer without a cast fileman.c:62: warning: passing arg 2 of `strcpy' makes pointer from integer without a cast fileman.c: In function `fileman_completion': fileman.c:215: warning: assignment makes pointer from integer without a cast ld: Undefined symbols: _add_history _completion_matches _readline _rl_attempted_completion_function _rl_readline_name _xmalloc
Oh well, perhaps it's a bug in the code... though that doesn't make any sense since it's in the man page of readline...
     
Dedicated MacNNer
Join Date: Sep 2001
Location: San Jose CA
Status: Offline
Reply With Quote
Aug 9, 2004, 11:36 AM
 
Hi,

You need to tell cc that it needs to link with readline. Try adding '-lreadline' to the end of your command line.

--ranga
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Aug 9, 2004, 12:13 PM
 
Originally posted by ranga:
Hi,

You need to tell cc that it needs to link with readline. Try adding '-lreadline' to the end of your command line.

--ranga
I'm using the command 'cc -I/sw/include -I/sw/include/readline -L/sw/lib -Ireadline fileman.c'

and am still getting the same errors:

Code:
fileman.c: In function `dupstr': fileman.c:61: warning: passing arg 1 of `strlen' makes pointer from integer without a cast fileman.c:62: warning: passing arg 2 of `strcpy' makes pointer from integer without a cast fileman.c: In function `fileman_completion': fileman.c:215: warning: assignment makes pointer from integer without a cast ld: Undefined symbols: _add_history _completion_matches _readline _rl_attempted_completion_function _rl_readline_name _xmalloc
I tired variations for the command (taking out certain parts, adding others, etc) but all give me errors.

If you want to take a look at the source file, you can find it here.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Aug 9, 2004, 12:25 PM
 
Originally posted by itistoday:
I'm using the command 'cc -I/sw/include -I/sw/include/readline -L/sw/lib -Ireadline fileman.c'
You've misread. You are using the command cc -I/sw/include -I/sw/include/readline -L/sw/lib -Ireadline fileman.c. He said to use the command cc -I/sw/include -I/sw/include/readline -L/sw/lib -lreadline fileman.c. Lowercase L.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Aug 9, 2004, 01:10 PM
 
Originally posted by Chuckit:
You've misread. You are using the command cc -I/sw/include -I/sw/include/readline -L/sw/lib -Ireadline fileman.c. He said to use the command cc -I/sw/include -I/sw/include/readline -L/sw/lib -lreadline fileman.c. Lowercase L.
Haha! Man, we really should be putting these things in code tags shouldn't we Damn font... can't tell the difference.

Thanks everyone for your help! It compiles fine now.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:07 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2