[英]Linker Error - typedef struct
I have a compiling/linking error as follows: 我有一个编译/链接错误如下:
Undefined symbols for architecture x86_64:
"_memory_table", referenced from:
_initialize in main.o
linker command failed with exit code 1
The problem may be in the .h file below. 问题可能出在下面的.h文件中。 Have I done anything wrong with my typedef structs? 我的typedef结构有什么问题吗? The main.c simply calls initialize(). main.c只调用initialize()。 The initialize() fuction is below. initialize()函数如下。 For brevity, I have taken out all of the #define macros. 为简洁起见,我已经取出了所有#define宏。 Main is included further down the code. 主要包含在代码的下方。
Thanks. 谢谢。
//globals.h
#ifndef memory_manager_globals_h
#define memory_manager_globals_h
/******** Memory Table Entry Data Structure**********/
typedef struct
{
uint32_t block_address;
uint32_t next_free_block;
}mem_table_entry_t;
/******** Memory Table Data Structure**********/
typedef struct
{
mem_table_entry_t two_kib[8];
mem_table_entry_t one_kib[16];
mem_table_entry_t half_kib[32];
mem_table_entry_t quarter_kib[64];
mem_table_entry_t eighth_kib[128];
}mem_table_t;
extern mem_table_t memory_table;
#endif
... ...
//MAIN.C
#include <stdio.h>
#include "globals.h"
void initialize(void)
{
int block_count = 0; //
uint32_t dynamic_address = HEAP_START;
while(block_count <= INITIALIZE_BLOCK_COUNT)
{
if((block_count >= TWO_KIB_LO) && (block_count < TWO_KIB_HI))
{
memory_table.two_kib[block_count].block_address = HEAP_START;
dynamic_address = dynamic_address + 0x800;
memory_table.two_kib[block_count].next_free_block = dynamic_address;
block_count++;
}
...
[SOLVED] The correct format of the .h file should be as follows: [已解决] .h文件的正确格式应如下所示:
/******** Memory Table Entry Data Structure**********/
typedef struct
{
uint32_t block_address;
uint32_t next_free_block;
}mem_table_entry_t;
/******** Memory Table Data Structure**********/
typedef struct
{
mem_table_entry_t two_kib[8];
mem_table_entry_t one_kib[16];
mem_table_entry_t half_kib[32];
mem_table_entry_t quarter_kib[64];
mem_table_entry_t eighth_kib[128];
}mem_table_t;
mem_table_t memory_table;
extern mem_table_t memory_table;
You are missing a definition of memory_table
. 您缺少memory_table
的定义。 The extern
line is a declaration, not a definition. extern
行是声明,而不是定义。
Add this line to your C file to fix the linking problem: 将此行添加到您的C文件以修复链接问题:
mem_table_t memory_table;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.