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


|