• 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: Linker error with std C tool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linker error with std C tool


  • Subject: Re: Linker error with std C tool
  • From: Chris Espinosa <email@hidden>
  • Date: Tue, 13 Oct 2009 11:29:25 -0700

On Oct 13, 2009, at 8:21 AM, McLaughlin, Michael P. wrote:

> This is going to sound unbelievably stupid but I never tried to use Xcode
> for a *std C tool* before, just C++, Cocoa, etc.  [Xcode 3.1.3, OS 10.5.8]
>
> The project template works. [Hello, world!]
>
> I created myFile.c file and its header, place them in a subdirectory of the
> project directory and added that directory to the project (drag-and-drop).
> main.c and myFile.c are both checked in the source list.  main.c includes
> myFile.h and calls a function myFunc() in myFile.c.  myFunc shows up as a
> project symbol.
>
> The project compiles but I get a linker error:
>
> _myFunc
> symbol not found
>
> When I check Build Results, it shows only main.o being built even though,
> when I select the target, myFile shows up in the list of sources for the
> tool.
>
> If I add
>
> #include "myFunc.c"
>
> to main.c, there is no linker error.

You should never need to include a source file from another source file.  It leads to multiple definition errors more often than not.

> I am completely bewildered.  Clearly, I'm missing something basic.  Could
> someone please tell me what it is?

C and C++ have different ways of representing the same exported symbol.  If you define a symbol in a C file and use it from a C++ file, you must enclose its definition in the header file in an

extern "C" {

}

block.  This is a standard paradigm in all C/C++ development systems.

Chris _______________________________________________
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: 
 >Linker error with std C tool (From: "McLaughlin, Michael P." <email@hidden>)

  • Prev by Date: Re: Linker error with std C tool -- SOLVED
  • Next by Date: [Xcode] 3.1.2 eating repositories?
  • Previous by thread: Linker error with std C tool
  • Next by thread: Re: Linker error with std C tool
  • Index(es):
    • Date
    • Thread