• 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: Link error using C dylib from C++ dylib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Link error using C dylib from C++ dylib


  • Subject: Re: Link error using C dylib from C++ dylib
  • From: Jonathan Prescott <email@hidden>
  • Date: Thu, 18 Sep 2008 12:15:13 -0400

The other, more traditional, way of handling this situation is to add the extern "C" directive into your csource.h file like this:

#ifndef CSOURCE_H // Assuming you are putting guard defines for all your header file
#define CSOURCE_H


#if defined( __cplusplus )
extern "C" {
#endif

.... the contents of csource.h ...

#if defined( __cplusplus )
}
#endif

#endif

The __cplusplus pre-processor macro is defined by C++ compilers, so, if you are compiling with a C++ compiler, the macro is defined, and the extern "C" wrapper gets processed. If you are compiling with a C- compiler (like when you build your library), the macro is not defined, and gets ignored by the compiler. Now, you can simply #include csource.h no matter what type of code you are writing.

Jonathan

On Sep 18, 2008, at 10:00 AM, Daniel Luis dos Santos wrote:

Hello,

I have an xcode project with one C source file and header file. These are built into a BSD dylib.
Have another xcode project with a Cpp source file and header file. I include the C source in the Cpp file in which one of the class's methods I call the C function. The C header file inclusion is surrounded by a extern "C" { #include "csource.h" }. I then drag the built dylib from the C project into the link with libraries build phase of the C++ target. The function from the C source is not found by the linker.


Do I have to do anything else to get this to link ?
_______________________________________________
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

_______________________________________________ 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: 
 >Link error using C dylib from C++ dylib (From: Daniel Luis dos Santos <email@hidden>)

  • Prev by Date: Re: Link error using C dylib from C++ dylib
  • Next by Date: Re: Build error - strip failed (3.1.1)
  • Previous by thread: Re: Link error using C dylib from C++ dylib
  • Next by thread: Re: "Refactor..." menu item is disabled
  • Index(es):
    • Date
    • Thread