Re: Forcing a single source file to compile with different compiler
Re: Forcing a single source file to compile with different compiler
- Subject: Re: Forcing a single source file to compile with different compiler
- From: Rick Altherr <email@hidden>
- Date: Wed, 16 May 2007 11:13:41 -0700
Or add a preprocessor checks to declare it as extern "C" when using
the header under C++:
#ifdef __cplusplus__
extern "C" {
#endif
void foo();
#ifdef __cplusplus__
}
#endif
Now, the source file can be a .c (which it should be since it
contains only C and no C++) and the .h can be used in C or C++.
--
Rick Altherr
Architecture and Performance Group
email@hidden
On May 16, 2007, at 11:07 AM, Mike wrote:
Except that this is a library file used in many projects. If the
file's extension is .c then the code won't link in projects that
are using C++. Some of my projects need the code in this file for C+
+-based projects, some others for C-based projects.
In fact, the best solution for a library of files of C routines is
to simply "extern C" them in the code and leave the file extension
at ".cp". That allows both C and C++ code to be compiled in the
same file, but also allows other files that contain only C code to
link to the C routines in the .cp file.
Thanks,
Mike
Scott Tooker wrote:
There are two good solutions here:
- By far, the best thing to do is change the file extension on the
file to .c. This is the cleanest way to deal with this.
- If for some reason you can't change the file extension on the
file itself, bring up the inspector for the file reference and
change the filetype. This is better than adding "-x c" since the
debugger will also honor the filetype set in the inspector.
Scott
On May 15, 2007, at 11:12 PM, Mike wrote:
I have a Carbon project in XCode 2.4.1. I have a .cp library file
but for this project I want just that one file to compile as a C,
not a C++ file. Is there a way to force XCode to use the C
compiler on just that one file instead of using the C++ compiler?
Thanks,
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.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:
amorose.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:
40apple.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