Re: Undefined Symbols when linking global logging function
Re: Undefined Symbols when linking global logging function
- Subject: Re: Undefined Symbols when linking global logging function
- From: Aaron Montgomery <email@hidden>
- Date: Wed, 16 Aug 2006 15:56:42 -0700
Missed the earlier mails, so I may be off track here.
Try wrapping the declaration in an extern "C" (not the definition).
When the compiler is reading the C file (log.c), it is creating
WriteToLog with C linkage, you need to tell the C++ compilers that
the declaration (in the header) is for a function that will come with
C linkage. So you might want to try something like the following to
handle the C++ files. I'm guessing something similar works for the
Obj-C case as well, or maybe it is unneeded if Obj-C uses the same
linking convention as C (I'm more familiar with the C++ case if you
haven't guessed).
Header:
#ifdef __cplusplus
// if we are reading the header from within the C++ compiler
// declare the function as having C linkage
extern "C" {
#endif
void WriteToLog(const char*);
#ifdef __cplusplus
}
#endif
Source:
void WriteToLog(const char* str)
{
puts(str);
}
Hope that helps,
Aaron
On Aug 16, 2006, at 3:14 PM, Ari Benzane wrote:
On 16 Aug 2006, at 12:07, Ari Benzane wrote:
I'm developing a large application consisting of both C,C++ and
Objective-C++ sources. To help with debugging, all logging to the
console is handled by a very simple utility file:
This works fine in the development build, but when I try a release-
build with XCode 2.2 (GCC 4.0), I get this error:
Undefined symbols:
WriteToLog(char const *)
_writeToLog
collect2: Id returned 1 exit status
Is this a C function used in C++ code? You might want to wrap the
definition with
extern "C" {
}
------------
David Dunham email@hidden http://www.pensee.com/dunham/
"No matter how far you have gone on a wrong road, turn back." -
Turkish proverb
Sorry I don't follow you - I tried that but got a syntax error. It
seems to be a problem with the way GCC is linking the project - if
I include the entire function inside the header file, I get a
multiple-symbol defined error.
___________________________________________________________All new
Yahoo! Mail "The new Interface is stunning in its simplicity and
ease of use." - PC Magazinehttp://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40monsterworks.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden