2

When I try to compile my code, I'm getting the error:

.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_init (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_lock (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_unlock (referred from lab4_t0.o).

I read that "Undefined symbol errors can occur when a function is declared (as is the case for the lock functions in lock.h), but it is not properly implemented." But I feel that I am implementing all the functions in lock.h properly since all the functions are of type voidand I don't return anything. So I don't know what I could be doing wrong to get this error.

Any help would greatly be appreciated!

Note: Please let me know if I need to provide more code. I don't think I need to write what I put in the function implementations of lock.h since I feel all you need to know is that the function implementations do not return anything, but please let me know if I need to include that.

Code

lock.c

#include "lock.h"

extern process_t * current_process; 
extern process_t * process_queue;

void l_init(lock_t* l){
    //Does stuff but never type return or return anything
}

void l_lock(lock_t* l){
    //Does stuff but never type return or return anything
}

void l_unlock(lock_t* l){
    //Does stuff but never type return or return anything
}

lock.h

#ifndef __LOCK_H_INCLUDED__
#define __LOCK_H_INCLUDED__

#include "3140_concur.h"
#include "shared_structs.h"

void l_init(lock_t* l);

void l_lock(lock_t* l);

void l_unlock(lock_t* l);

#endif /* __LOCK_H_INCLUDED */

3140_concur.c

#include "3140_concur.h"
#include <stdlib.h>

3140_concur.h

#ifndef __3140_CONCUR_H__
#define __3140_CONCUR_H__

#include <stdlib.h>
#include <fsl_device_registers.h>
#include "process.h"

void process_blocked (void);

void process_terminated (void);

unsigned int * process_stack_init (void (*f)(void), int n);

void process_stack_free (unsigned int *sp, int n);

void process_begin (void);

#endif

process.h

#include <stdlib.h>
#include <fsl_device_registers.h>
#include "3140_concur.h"

struct process_state;
typedef struct process_state process_t;

unsigned int * process_select (unsigned int * cursp);

extern process_t * current_process; 
extern process_t * process_queue;

void process_start (void);

int process_create (void (*f)(void), int n);

process.c

(I do process_t* process_queue = NULL; & process_t* current_process = NULL; b/c I want them to be NULL before any functions are called)

#include "3140_concur.h" 
#include "shared_structs.h"
#include <stdlib.h> 
#include <fsl_device_registers.h>

process_t* process_queue = NULL;
process_t* current_process = NULL;

lab4_t0.c

#include "process.h"
#include "utils.h"
#include "lock.h"

lock_t l;

\\uses functions in lock.h

Update

Build output

*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling 3140_concur.c...
compiling lab4_t0.c...
lab4_t0.c(42): warning:  #111-D: statement is unreachable
        return 0;       
lab4_t0.c: 1 warning, 0 errors
compiling process.c...
process.c(100): warning:  #1-D: last line of file ends without a newline
  }
process.c: 1 warning, 0 errors
linking...
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_init (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_lock (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_unlock (referred from lab4_t0.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 3 error messages.
".\Objects\Lab4.axf" - 3 Error(s), 2 Warning(s).
Target not created.
Build Time Elapsed:  00:00:39
14wml
  • 4,048
  • 11
  • 49
  • 97
  • Header file mostly does not sence at linker errors. you need to specify library or object file to linker where required symbols is defined. – oklas Apr 12 '17 at 04:05
  • @oklas I'm sorry I do not understand. Could you please specify what I need to do in terms of my code? – 14wml Apr 12 '17 at 04:09
  • @15ongm can you show how are you trying to compile the code? Most probably you are not using the lock.o while linking. – Ajay Brahmakshatriya Apr 12 '17 at 04:10
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – too honest for this site Apr 12 '17 at 04:10
  • Most possible your code have not errors and nothing to specify in its terms. This is build configuration problem. – oklas Apr 12 '17 at 04:12
  • @AjayBrahmakshatriya What do you want specifically? B/c to compile I just click a button. Is there smtg I could print to give you more information? I'm sorry if I annoy you if I sound very uneducated about this but much of this stuff wasn't explained to me – 14wml Apr 12 '17 at 04:12
  • @oklas Yeah that's another possibility I read about. How can I check to see if the build configuration is right (I use Keil uVision)? – 14wml Apr 12 '17 at 04:13
  • How did you compile your program? – user253751 Apr 12 '17 at 04:13
  • When you click the compile button, there might be a compile log or a build log being generated. Could you copy it and share? Also which IDE are you using? Which operating system? – Ajay Brahmakshatriya Apr 12 '17 at 04:13
  • You say click button - mean you use development environment, so you need to open configuartions of current project or build unit and add required library. Read in manual about `l_lock` and so on which library need to add. – oklas Apr 12 '17 at 04:15
  • @AjayBrahmakshatriya I'm using Keil uVision & Windows. I put the build output in my question post – 14wml Apr 12 '17 at 04:16
  • @oklas He has defined the missing symbols in a separate c file. So it is not a missing library but an issue with not including the lock.c in the project. – Ajay Brahmakshatriya Apr 12 '17 at 04:16
  • I notice that it did not compile lock.c. Why not? – user253751 Apr 12 '17 at 04:17
  • @immibis I wish I knew. I only am following directions I was told to do. So hypothetically following those direction lock.c should be compiled but I guess not. – 14wml Apr 12 '17 at 04:18
  • @15ongm you can see in the build output that lock.c is not being compiled. Are you sure you have added it in the project? Or it just resides it the source directory? – Ajay Brahmakshatriya Apr 12 '17 at 04:18
  • @15ongm can you check if lock.c appears in the source folder under the "Project" tab on the left. I am assuming this is the Keil uVision you are using - http://www2.keil.com/mdk5/uvision/ – Ajay Brahmakshatriya Apr 12 '17 at 04:20
  • @AjayBrahmakshatriya Yeah I realized I didn't add it. I'm compiling it right now to see if it works now – 14wml Apr 12 '17 at 04:21
  • @AjayBrahmakshatriya omg it compiles! I can't believe it was that stupid of a mistake! THANK-YOU! – 14wml Apr 12 '17 at 04:21

1 Answers1

1

Thanks to @AjayBrahmakshatriya, it turns out I didn't add lock.c to my project. That fixed everything. Whew.

14wml
  • 4,048
  • 11
  • 49
  • 97