简体   繁体   中英

Undefined symbols for architecture x86_64 : Cadventure-txt

I am trying to get Cadventure-txt to compile but I keep getting the Undefined symbols for architecture x86_64 error. I read on SO to find a possible solution but, so far, to no avail.

I made no change to the files available on github. If anyone can make sense of the following error, it would be really nice :) I am quite new to C and programming so I don't have much of a clue as to where to begin debugging such an error.

Here's the full error:

Undefined symbols for architecture x86_64:
  "_is_command", referenced from:
      _init in main.o
      _play in main.o
  "_is_letter", referenced from:
      _init in main.o
      _play in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The two functions _is_command and _is_letter are defined as inline .

You said you are using XCode as compiler, which uses Clang.

By default, Clang builds C code in GNU C11 mode, so it uses standard C99 semantics for the inline keyword. In C99, inline means that a function's definition is provided only for inlining, and that there is another definition (without inline) somewhere else in the program.

But there are no other definitions of these functions in the program, thus the error with undefined symbols at link time.

Some solutions:

  • Define the functions as static inline .
  • Remove the inline .
  • Add the non-inline definition for the functions.
  • Compile in GNU C89 mode with std=gnu89 .

Read more about this here .

error lines starting with ld come from ld , the linker.

It says that it can't find a symbol (ie. a function name) that you use ; probably, you're simply not linking against the file containing these functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM