• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: What should be a simple linking problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What should be a simple linking problem


  • Subject: Re: What should be a simple linking problem
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 9 Apr 2009 14:59:59 -0500

On Apr 9, 2009, at 2:45 PM, Richard L. Aurbach wrote:

My application uses an external C-language library (built as a static library with a .a extension [ libSCCE.a ]). The library calls an external function SCCE_TempLexName(char*) which it expects the host application to provide.

My (host) application implements this function as follows:

in SSCE_TempLexName.h :
#if defined(__cplusplus)
extern "C" {
#endif

void	SSCE_TempLexName (
			char * 			outPath );

#if defined(__cplusplus)
}
#endif


in SSCE_TempLexName.cpp: void SSCE_TempLexName ( char * outPath ) { ... C++ body - the content doesn't matter here }

The implementation is explicitly (and needs to be) a C++ function because it uses C++ class objects in its implementation.

MY PROBLEM:
The linker has an undefined symbol error:
  "SSCE_TempLexName(char*)", referenced from:
      getTempFileName()     in libSCCE.a(DFTLEX.o)
      saveLexFile(DFTLEX*)     in libSCCE.a(DFTLEX.o)


This worked in my CodeWarrior projects, but it obviously doesn't here. Can someone point out what I am doing wrong??

In C++, the symbol names for functions include their signature -- the number and types of the arguments.


So, in C, the symbol name for the above function would be "SSCE_TempLexName" but in C++ it's a mangled form of "SSCE_TempLexName(char*)". Two different symbol names, which don't match. This is necessary to allow overloading in C++, as well as type- safety.

The declaration using extern "C" in the header tells the compiler to use the C-style symbol for that function instead of the C++-style one. You need to do the same in the .cpp file. I don't recall if it's sufficient to just include the header from the source file -- that is, to include a declaration with extern "C" before the definition -- or if you have to put extern "C" on the definition, too.

Cheers,
Ken

_______________________________________________
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


References: 
 >What should be a simple linking problem (From: "Richard L. Aurbach" <email@hidden>)

  • Prev by Date: Re: What should be a simple linking problem
  • Next by Date: Re: What should be a simple linking problem
  • Previous by thread: Re: What should be a simple linking problem
  • Next by thread: Xcode documentation window crashing frequently
  • Index(es):
    • Date
    • Thread