Undefined symbols for architecture x86_64
TLHorse opened this issue · 2 comments
TLHorse commented
I'm reading this chapter of BuildYourOwnLisp Book, and I'm trying to write a tiny language Venus
(just for fun) using mpc
, my directory tree (for now) looks like this:
Venus
┠ mpc.c
┠ mpc.h
┗ parsing.c
In parsing.c
:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mpc.h"
#ifdef _WIN32
static char buffer[2048];
char* readline(char* prompt) {
fputs(prompt, stdout);
fgets(buffer, 2048, stdin);
char* cpy = malloc(strlen(buffer)+1);
strcpy(cpy, buffer);
cpy[strlen(cpy)-1] = '\0';
return cpy;
}
void add_history(char* unused) {}
#else
#ifdef __linux__
#include <editline/readline.h>
#include <editline/history.h>
#endif
#ifdef __MACH__
#include <editline/readline.h>
#endif
#endif
int main(int argc, char **argv)
{
mpc_parser_t* Number = mpc_new("number");
mpc_parser_t* Operator = mpc_new("operator");
mpc_parser_t* Expression = mpc_new("expression");
mpc_parser_t* Venus = mpc_new("venus");
mpca_lang(MPCA_LANG_DEFAULT,
"\
number : /-?[0-9]+/ ; \
operator : '+' '-' '*' '/' ; \
expression : <number> | '(' <operator> <expr>+ ')' ; \
venus : /^/ <operator> <expression>+ /$/ ; \
", Number, Operator, Expression, Venus);
printf("\
__ __\n\
\\ V / enus 1.0.0\n\
\\ / %s in %s\n\
V Tip: Use :exit or :help command to quit / get info.\n\
",
__TIME__, __DATE__);
// Main Loop
while (1)
{
char *input = readline("\n> ");
add_history(input);
// Check if executing :exit or :help.
if (strcmp(input, ":exit") == 0)
exit(0);
if (strcmp(input, "") == 0)
continue;
if (strcmp(input, ":help") == 0)
{
printf("\nAuthor: TLHorse\nA tiny programming lang.\n");
continue;
}
mpc_result_t result;
if (mpc_parse("<stdin>", input, Venus, &result)) {
mpc_ast_print(result.output);
mpc_ast_delete(result.output);
} else {
mpc_error_print(result.error);
mpc_error_delete(result.error);
}
free(input);
}
return 0;
}
NOTE THAT my mpc expressions in parsing.c
isn't done yet.
When I finish my code, I used
cc -std=c99 -Wall parsing.c mpc.c -ledit -lm -o parsing
But 2 warnings and 1 error generated:
tlhorse@tlhmac Venus % cc -std=c99 -Wall parsing.c mpc.c -ledit -lm -o parsing
parsing.c:78:13: warning: implicit declaration of function 'mpc_error_print' is invalid in C99 [-Wimplicit-function-declaration]
mpc_error_print(result.error);
^
parsing.c:79:13: warning: implicit declaration of function 'mpc_error_delete' is invalid in C99 [-Wimplicit-function-declaration]
mpc_error_delete(result.error);
^
2 warnings generated.
Undefined symbols for architecture x86_64:
"_mpc_error_delete", referenced from:
_main in parsing-4a1667.o
"_mpc_error_print", referenced from:
_main in parsing-4a1667.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Actually the warnings are insignificant, but the error is torturing me.
WHY THE HELL THAT the symbols _mpc_error_delete
and _mpc_error_print
are ALWAYS not found for architecture x86_64???
I'm just a newbie. It would be grateful if someone could help me.
TLHorse commented
By the way, is there any connection between the error and the 2 warnings?
TLHorse commented
Sorry : ) , it should be mpc_err_delete, not error.