Re: C with C++ in xcode
Re: C with C++ in xcode
- Subject: Re: C with C++ in xcode
- From: Joe Kurtz <email@hidden>
- Date: Wed, 28 Sep 2005 16:41:15 -0700 (PDT)
Thanks again.
To summarize again: The error is when the linker tries
to link the c++ module that includes a call to a C
routine: "cfxn(argument types) undefined symbol" (even
though #include "cfoo.h" is in the c++foo.h file.
I will investigate with the suggestions below. BTW: I
am using build button in xcode, not sure what
command-line this translates to, but the build rules
in the target info window includes both c and c++
files using GCC 4.0.
For now, the c-files weren't so large so it was not
too hard translate them to classes and everything
works okay. I plan to use more c-code from various
sources, so this is only a temporary workaround for
me.
--- "E. Wing" <email@hidden> wrote:
> > From: Joe Kurtz
> > Thanks for the replies.
> >
> > I've tried both Eric's and Markian's suggestion.
> Nope.
> > I get the same error reported by the linker
> (undefined
> > symbols).
>
> It's hard to say what's going on. One thing I think
> you do need to
> make sure of is that you compile the C code as C and
> not C++. Is the C
> code directly included in your project or are you
> linking against it?
>
> I think if you use the first method (Eric Albert's)
> and put the guards
> in all your C header files, then this will be
> probably be handled
> automatically for you.
>
> If you use the second method (or my variation of the
> second method),
> you have to be more careful about how your C code
> gets compiled.
>
> For example, if you have a main.cpp that uses a
> foo.h and foo.c, if
> you put the __cplusplus guard in the main.cpp (the
> second method) and
> not foo.h, then you have to make sure you compiled
> foo.c with the C
> compiler (gcc) and not the C++ compiler (g++). In
> this case, this
> command should fail to link:
> g++ main.cpp foo.c
> (If you use the first method, this should work.)
>
> Conversely, if you leave out the header guards
> entirely and run this
> command, everything should compile under C++ and I
> think it should
> also work. But if you built foo using just the C
> compiler and main
> with the C++ compiler, when you try to link them,
> they will fail.
>
>
> If you are using the second method, and you think
> your C code might be
> being compiled as C++, you might try building the C
> code into a
> separate library first so there is no risk of
> contamination. Then you
> just need to make sure you added all your cplusplus
> guards in your C++
> code. If this continues to fail, it might mean you
> missed a guard, or
> there is something else wrong that's unrelated to
> this, or I am
> totally off the mark.
>
> > Maybe there's something else amiss here.
> > I note that the c functions I want to use are
> > returning float** types.
> > (could this have implications?)
>
> As far as I know, this shouldn't be a problem.
> _______________________________________________
> 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
>
______________________________________________________
Yahoo! for Good
Donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/
_______________________________________________
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