Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: Using the s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 22 Topic 4074 of 4262
Post > Topic >>

Re: Using the same source file from other source files

by Hal Vaughan <hal@[EMAIL PROTECTED] > Mar 20, 2008 at 09:28 AM

Hal Vaughan wrote:

> Richard Heathfield wrote:
....
>> To make the files all work together, you have to "link" them.
>> 
>> In gcc, it works like this:
>> 
>> gcc ...lots of flags and stuff... -c -o foo.o foo.c
>> gcc ...lots of flags and stuff... -c -o bar.o bar.c
>> gcc ...lots of flags and stuff... -c -o baz.o baz.c
>> 
>> -c means "just compile, don't try to link", and translates source files
>> to object files, but you don't get a program yet...
>> 
>> gcc ...lots of flags and stuff... -o myprog foo.o bar.o baz.o
> 
> Now that I've done this, there's one point I'm still having problems
with.
> I have a file with a function like this:
> 
> void setour****t(string);
> 
> I'm calling it from another file, so I get this error:
> 
> hdlinuxio.h:5: error: variable or field ?setour****t? declared void
> hdlinuxio.h:5: error: ?string? has not been declared
> 
> I notice the error is for the header file, not the source file.  I've
> experimented and it seems whenever I'm using a function with a string as
a
> parameter and I'm calling it from one file when it's in another, I get
> this
> as a problem.  I tried adding "#include <string>" to the start of the
> header file and it makes no difference.
> 
> Why won't it let me use a function with a string as a parameter in
another
> file?

I got that working by using the needed #include statements and adding
"using
namespace std;"  (Yes, I know, better to use std:: at each place needed,
but for now I'm just making sure it works.)

There's one problem that didn't show up until I fixed this one.

I have my own library with this function:

void parseargs(int, char*);

I call it from the main function with argc and argv.  When I've compiled
this without using make there was no problem, but now that I'm using make
(or compiling it by hand, with the changes make needed), I get this error:

halcyon.cpp: In function ?std::map<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, std::basic_string<char,
std::char_traits<char>, std::allocator<char> >,
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, std::allocator<std::pair<const
std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >
> parseargs(int, char***)?:
halcyon.cpp:16: error: invalid conversion from ?char**? to ?char?
halcyon.cpp:16: error:   initializing argument 1
of ?std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT,
_Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits =
std::char_traits<char>, _Alloc = std::allocator<char>]?

The thing is, at this point, halcyon.cpp has been compiled already and the
file being compiled is hdcmd.cpp, the one that calls parseargs() in
halcycon.cpp.

As I said, it compiled okay before, but now it won't.  Since then (when it
compiled), I've put the function prototypes in header files.  Could the
header file with this function prototype need an include that the source
file itself doesn't?

Again, thanks!

Hal
 




 22 Posts in Topic:
Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 07:10:47 
Re: Using the same source file from other source files
Richard Heathfield <rj  2008-03-20 07:25:59 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 07:29:28 
Re: Using the same source file from other source files
"Jim Langston"   2008-03-20 00:55:37 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-20 15:31:49 
Re: Using the same source file from other source files
Richard Heathfield <rj  2008-03-20 08:36:26 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 08:50:25 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 09:28:25 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 09:37:01 
Re: Using the same source file from other source files
"Chris ( Val )"  2008-03-21 03:37:07 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-25 17:22:35 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 15:08:23 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 15:37:26 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 15:48:02 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 15:56:20 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-20 17:11:20 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 17:54:57 
Re: Using the same source file from other source files
Philip Potter <pgp@[EM  2008-03-21 10:03:58 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 19:34:41 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 20:31:21 
Re: Using the same source file from other source files
Ben Bacarisse <ben.use  2008-03-20 19:45:49 
Re: Using the same source file from other source files
Hal Vaughan <hal@[EMAI  2008-03-20 20:34:08 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Sep 5 2:43:25 CDT 2008.