On Oct 23, 6:05 pm, "Howard" <m...@here.comwrote:
"tragomaskhalos" <dave.du.verg...@logicacmg.comwrote in message
[...]
I think your problem is that, based on the extension,
these are C rather than C++ files.
In C++ a1 and a2 have internal linkage so you should have
no problem, but the rules in C, IIRC, are different.
So, rename the files to cpp or otherwise compile them as
C++. If they must remain C, put "static" in front of
the variable definitions.
I'm pretty sure that's not the problem.
I'm almost 100% sure that it is the problem. Most of the C++
compilers I know will compile a file with the extension .c as C.
And in C, const doesn't mean internal linkage.
The link error is probably because
there are no include guards in the header file, and the header file is
included by two files in the same compilation unit.
That would cause a compile error, not a link error.
But you are correct that those should be .cpp files if he's
using C++. The main reason for that is because certain IDEs
will use the C compiler instead of the C++ compiler for files
with a .c extension.
Not the IDE's. Most "compilers" are actually driver programs,
which invoke different compilers, the linker, perhaps the
librarian, etc., depending on the options given and the filename
extensions. While g++ and Sun CC will compile .c as C++, VC++
(command cl) doesn't, and historically, I believe that many
others didn't either. (The fact that g++ and Sun CC don't
actually surprised me. I would, in fact, consider this a bug:
if I want to compile and link an application with both C and
C++, I want the C compiled as C, but I still need to invoke C++
for the link to work correctly.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34