Laurent Crivello
Laurent Crivello

Reputation: 3931

Undefined symbols for architecture x86_64 when linking c project

I try to compile the picoc project into xcode. No external libraries, just .c and .h files that I imported in the Command Line Tool C project.

All .c files compile without issue, but when XCode is linking, I get these messages:

    Undefined symbols for architecture x86_64:
  "_BasicIOInit", referenced from:
      _PicocInitialise in platform.o
  "_CStdOut", referenced from:
      _PrintSourceTextErrorLine in platform.o
      _PlatformVPrintf in platform.o
  "_MathFunctions", referenced from:
      _IncludeInit in include.o
  "_MathSetupFunc", referenced from:
      _IncludeInit in include.o
  "_PicocPlatformScanFile", referenced from:
      _IncludeFile in include.o
  ...

The command giving the error is the following:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -v -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/laurent/Library/Developer/Xcode/DerivedData/Pico-dhfwbamkhiyphjcwuncbwjsyjlax/Build/Products/Debug -F/Users/laurent/Library/Developer/Xcode/DerivedData/Pico-dhfwbamkhiyphjcwuncbwjsyjlax/Build/Products/Debug -filelist /Users/laurent/Library/Developer/Xcode/DerivedData/Pico-dhfwbamkhiyphjcwuncbwjsyjlax/Build/Intermediates/Pico.build/Debug/Pico.build/Objects-normal/x86_64/Pico.LinkFileList -mmacosx-version-min=10.8 -o /Users/laurent/Library/Developer/Xcode/DerivedData/Pico-dhfwbamkhiyphjcwuncbwjsyjlax/Build/Products/Debug/Pico

The Pico.LinkFileList file contains properly the list of all necessary .o files.

As all the unfound functions are in the properly compiled .c files (and compiled as .o), what should I do to avoid these errors ? Thanks.

Upvotes: 1

Views: 1494

Answers (3)

Purushottam Sain
Purushottam Sain

Reputation: 286

Adding Pico to the Target Dependencies list worked for me after the same situation. (from Pico i mean the xcode project folder from where we have created library)

reference : https://github.com/bulldog2011/pico

Upvotes: 1

Laurent Crivello
Laurent Crivello

Reputation: 3931

In case it can help someone, I found out that some #ifdef commands were excluding the functions to be compiled.

Upvotes: 0

trojanfoe
trojanfoe

Reputation: 122458

Those symbols are in clibrary.c; you must have missed it from the list of source files to compile.

Your next question will doubtless be about libraries to link the executable with, and to solve that I would suggest you look at the Makefile.

Upvotes: 1

Related Questions