 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
LMario Guest
|
Posted: Fri Mar 11, 2005 9:13 pm Post subject: Unresolved external |
|
|
I have a program which calls a C function from a separate source file but I
keep getting unresolved external errors. When I add CPP functions (in a
sparate file) to my program I don't have any problems. Are there differences
to incorporte C o CPP functions to a CBuilder proyect. I can't simply rename
my C file to CPP because then when I compile I receive compilation errors.
|
|
| Back to top |
|
 |
Helmut Giese Guest
|
Posted: Fri Mar 11, 2005 9:33 pm Post subject: Re: Unresolved external |
|
|
On Fri, 11 Mar 2005 15:13:42 -0600, "LMario" <lefalme (AT) prodigy (DOT) net.mx>
wrote:
| Quote: | I have a program which calls a C function from a separate source file but I
keep getting unresolved external errors. When I add CPP functions (in a
sparate file) to my program I don't have any problems. Are there differences
to incorporte C o CPP functions to a CBuilder proyect. I can't simply rename
my C file to CPP because then when I compile I receive compilation errors.
While what Chris said is certainly true, may I add that you should |
maybe search for the root of the problem?
Actually, I usually advise people to compile even their C programs as
C++, because this lets the compiler sometimes find bugs. In other
words: If I had a C program which is not acceptable as a C++ program I
would have a very, very close look as to why - chances are high, that
I am doing something which I shouldn't do.
Of course just my 0.02.
Best regards
Helmut Giese
|
|
| Back to top |
|
 |
Chris Uzdavinis (TeamB) Guest
|
Posted: Fri Mar 11, 2005 10:01 pm Post subject: Re: Unresolved external |
|
|
[email]hgiese (AT) ratiosoft (DOT) com[/email] (Helmut Giese) writes:
| Quote: | While what Chris said is certainly true, may I add that you should
maybe search for the root of the problem?
Actually, I usually advise people to compile even their C programs as
C++, because this lets the compiler sometimes find bugs. In other
words: If I had a C program which is not acceptable as a C++ program I
would have a very, very close look as to why - chances are high, that
I am doing something which I shouldn't do.
Of course just my 0.02.
|
I agree that a C++ compiler can potentially catch bugs that a C
compiler permits. Or, alternately, at least catches things that are
questionable or not portable. (Sometimes C code ends up pasted in a
C++ file afterall.)
However, if the full file is entirely C, the production code probably
should be built with a C compiler. First of all, at least with g++
3.2, we have some C code that runs faster when compiled as C than as
C++. Second, other languags may use C functions but can't use C++
functions. Maybe that's important.
--
Chris (TeamB);
|
|
| Back to top |
|
 |
Duane Hebert Guest
|
Posted: Fri Mar 11, 2005 10:13 pm Post subject: Re: Unresolved external |
|
|
"Chris Uzdavinis (TeamB)" <chris (AT) uzdavinis (DOT) com> wrote
| Quote: | hgiese (AT) ratiosoft (DOT) com (Helmut Giese) writes:
While what Chris said is certainly true, may I add that you should
maybe search for the root of the problem?
Actually, I usually advise people to compile even their C programs as
C++, because this lets the compiler sometimes find bugs. In other
words: If I had a C program which is not acceptable as a C++ program I
would have a very, very close look as to why - chances are high, that
I am doing something which I shouldn't do.
Of course just my 0.02.
I agree that a C++ compiler can potentially catch bugs that a C
compiler permits. Or, alternately, at least catches things that are
questionable or not portable. (Sometimes C code ends up pasted in a
C++ file afterall.)
However, if the full file is entirely C, the production code probably
should be built with a C compiler. First of all, at least with g++
3.2, we have some C code that runs faster when compiled as C than as
C++. Second, other languags may use C functions but can't use C++
functions. Maybe that's important.
|
It's also possible that the OP has a library compiled in C. In this
case, the extern c stuff is necessary.
|
|
| Back to top |
|
 |
Helmut Giese Guest
|
Posted: Fri Mar 11, 2005 10:17 pm Post subject: Re: Unresolved external |
|
|
On Fri, 11 Mar 2005 17:01:36 -0500, Chris Uzdavinis (TeamB)
<chris (AT) uzdavinis (DOT) com> wrote:
Hi Chris,
you're way ahead of me
| Quote: | I agree that a C++ compiler can potentially catch bugs that a C
compiler permits. Or, alternately, at least catches things that are
questionable or not portable. (Sometimes C code ends up pasted in a
C++ file afterall.)
However, if the full file is entirely C, the production code probably
should be built with a C compiler. First of all, at least with g++
3.2, we have some C code that runs faster when compiled as C than as
C++. Second, other languags may use C functions but can't use C++
functions. Maybe that's important.
Well, even if this is the case (and only the OP can tell us) my advice |
would still be: If C code does not compile as C++ code, I would have a
very close look at the errors the C++ compiler identifies.
Then, in a second step, I'd switch back to C to - maybe - get more
performant code, offer a C-like interface or whatever.
Best regards
Helmut Giese
|
|
| Back to top |
|
 |
LMario Guest
|
Posted: Fri Mar 11, 2005 11:00 pm Post subject: Re: Unresolved external |
|
|
Thanks, now all is working.
"Chris Uzdavinis (TeamB)" <chris (AT) uzdavinis (DOT) com> wrote
| Quote: | "LMario" <lefalme (AT) prodigy (DOT) net.mx> writes:
I have a program which calls a C function from a separate source file
but I
keep getting unresolved external errors. When I add CPP functions (in a
sparate file) to my program I don't have any problems. Are there
differences
to incorporte C o CPP functions to a CBuilder proyect. I can't simply
rename
my C file to CPP because then when I compile I receive compilation
errors.
When you include the header that prototyptes the C functions, be sure
to tell the compiler that the contents should have C linkage.
extern "C" {
#include "mychdr.h"
}
The reason is that when you compile the C++ program that includes this
header, in that file the names get mangled because the functions are
thought to be C++ functions.
But when you compile the .c file itself, the names are not mangled
since it's not a c++ compiler. Thus, the mismatch is that the names
exported/imported do not mesh.
--
Chris (TeamB);
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|