Skip to content
Advertisement

Undefined symbols for architecture x86_64: “_read_line”, referenced from: _insert in inventory-82371b.o

Here is the callback with -v and warnings suppressed.

(base) goobnoob:~/c_projects/parts_database>gcc -w -v -o inventory inventory.c
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name inventory.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 253.9 -v -dwarf-column-info -resource-dir /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.0.2 -w -fdebug-compilation-dir /Users/goobnoob/c_projects/parts_database -ferror-limit 19 -fmessage-length 278 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/9d/665ynkj530z1n3999g4lzyvr0000gn/T/inventory-9d3105.o -x c inventory.c
clang -cc1 version 7.0.2 based upon LLVM 3.7.0svn default target x86_64-apple-darwin14.5.0
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.0.2/include
 /Library/Developer/CommandLineTools/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -w -o inventory /var/folders/9d/665ynkj530z1n3999g4lzyvr0000gn/T/inventory-9d3105.o -lSystem /Library/Developer/CommandLineTools/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_read_line", referenced from:
      _insert in inventory-9d3105.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here it is without warnings suppressed. But I don’t believe that they are causing the issue.

(base) goobnoob:~/c_projects/parts_database>gcc -o inventory inventory.c
inventory.c:93:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
inventory.c:178:14: warning: data argument not used by format string [-Wformat-extra-args]
        scanf("&d", &number);
              ~~~~  ^
inventory.c:212:75: warning: format specifies type 'long long' but the argument has type 'int' [-Wformat]
                printf("%7d       %-25s%lldn", inventory[i].number, inventory[i].name, inventory[i].on_hand);
                                       ~~~~                                             ^~~~~~~~~~~~~~~~~~~~
                                       %d
3 warnings generated.
Undefined symbols for architecture x86_64:
  "_read_line", referenced from:
      _insert in inventory-82371b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here is the code. It is a program for a very simple data base from a text book.

I truly believe my problem is with the compiling. It’s been a while since I’ve used gcc and can’t remember what I used. I won’t be able to see the compile commands as I’m out right now.

I also have the supporting readline.h and readline.c files. If you need those just ask.

I’m also using running this on UNIX in OS X Yosemite.

/* Maintains a parts database (array version) */

#include <stdio.h>
#include "readline.h"

#define NAME_LEN 25
#define MAX_PARTS 100

int main();
int find_part(int number);
void insert();
void search();
void update();
void print();

struct part {

        int number;
        char name[NAME_LEN + 1]; /* accounting for space needed for n break */

        int on_hand;

} inventory[MAX_PARTS];

int num_parts = 0; /* number of parts currently stored */

int find_part (int number);
void insert(void);
void search(void);
void update(void);
void print(void);

/******************************************************************
* main : Prompts the user to enter an operation code, then calls  *
*        a function to perform the requested action. Repeats until*
*        the user enters the command 'q'. Prints an error message *
*        if the user enters an illegal code.                      *
******************************************************************/

int main(void){

        char code;

        for (;;){

                printf("Enter operation code: ");

                scanf(" %c", &code);

                while(getchar() != 'n'); /* skips to end of line */

                switch (code) {

                        case 'i' : insert();
                                break;

                        case 's' : search();
                                break;

                        case 'u' : update();
                                break;

                        case 'p' : print();
                                break;

                        case 'q' : return 0;

                        default : printf("Illegal Code!n");

                }

                printf("n");

        }

}

/****************************************************************
* find_part : Looks up a part number in the inventory array.    *
*             Returns the array index if the part number is     *
*             found; otherwise, returns -1.                     *
****************************************************************/

int find_part (int number){

        int i;

        for (i = 0; i < num_parts; i++){

                if (inventory[i].number == number){

                        return i;

                }

                return -1;

        }

}

/*****************************************************************
* insert : Prompts the user for information about a new part and *
*          then inserts the part into the database. Prints an    *
*          error message and returns prematurely if the part     *
*          already exists or the database is full.               *
*****************************************************************/

void insert(void){

        int part_number;

        if (num_parts == MAX_PARTS) {

                printf("Database is full; can't add more parts.n");
                return;

        }

        printf("Enter part number: ");
        scanf("%d", &part_number);

        if (find_part(part_number) >= 0){

                printf("Part already exists");
                return;

        }

        /*Now we input the new part */

        inventory[num_parts].number = part_number;

        printf("Enter Part Name : ");
        read_line(inventory[num_parts].name, NAME_LEN); /* Getting Part Name of no longer length than NAME_LEN */

        printf("Enter quantity on hand : ");
        scanf("%d", &inventory[num_parts].on_hand);

        num_parts++; /* Updating amount of Parts in Storage */

}

/******************************************************************
* search : Prompts the user to enter a part number, then looks up *
*          the part in the database. If the part exists, prints   *
*          the name and quantity on hand; if not, prints an error *
*          message.                                               *
******************************************************************/

void search(void){

        int i, number;

        printf("Enter part number : ");
        scanf("%d", &number);

        i = find_part(number);

        if (i >= 0){ /* Verifying the part number exists (aka. did not return -1) */

                printf("Part name : %sn", inventory[i].name);
                printf("Quantity on hand : %dn", inventory[i].on_hand);

        }else{

                printf("Part not found!n");

        }

}

/****************************************************************
* update : Prompts the user to enter a part number. Prints an   *
*          error message if the part doesn't exist; otherwise,  *
*          prompts the user to enter change in quantity on hand *
*          and updates the data base.                           *
****************************************************************/

void update(void){

        int i, number, change;

        printf("Enter Part Number : ");
        scanf("&d", &number);

        i = find_part(number);

        if (i >= 0){

                printf("Enter change in quantity on hand : ");
                scanf("%d", &change);

                inventory[i].on_hand += change;

        }else{

                printf("Part not found!n");

        }

}

/*****************************************************************
* print : Prints a listing of all parts in the database, showing *
*         the part number, part name, and quantity on hand.      *
*         Parts are printed in the order in which they were      *
*         entered into the database.                             *
*****************************************************************/

void print(void){

        int i;

        printf("Part Number      Part Name                           Quantity on Hand");

        for (i = 0; i < num_parts; i++){

                printf("%7d       %-25s%lldn", inventory[i].number, inventory[i].name, inventory[i].on_hand);

        }

}

Advertisement

Answer

I also have the supporting readline.h and readline.c files. If you need those just ask.

You do not appear to be compiling readline.c at all. Try:

gcc -w -v -o inventory inventory.c readline.c
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement