如何改变数组从不同的文件在我的C代码?



我有两个单独的C文件,我需要改变一个名为NDEF.C的文件中的const u08_t NFC_NDEF_Message。这个文件没有导入到我的main.C中,但是当它被称为void initISO15693(u16_t parameters )时,它会进入另一个文件。我不明白这是怎么回事。我需要改变NDEF消息,但我不知道在哪里以及如何在主代码中访问它。任何帮助都会很感激。这两个文件在下面。

c:

/*
* main.c
*
* RF430FRL152H NFC Only Example Project
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 
* 
* 
*  Redistribution and use in source and binary forms, with or without 
*  modification, are permitted provided that the following conditions 
*  are met:
*
*    Redistributions of source code must retain the above copyright 
*    notice, this list of conditions and the following disclaimer.
*
*    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the 
*    documentation and/or other materials provided with the   
*    distribution.
*
*    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "NDEF.h"
#include "types.h"
#include "patch.h"
#include <rf430frl152h.h>
//*****************************FUNCTION PROTOTYPES********************************/
void DeviceInit(void);
//********************************************************************************/
/*********************** SUMMARY **************************************************************************************************
* This project *only* utilizes the RF stack (ISO15693) on the ROM of the RF430FRL15xH. This setup allows the user to make a
* custom application that is run from FRAM.  Only the RF13M vector that runs the RF stack needs to be pointing to its
* ROM location.
*/
/**************************************************************************************************************************************************
*   Code Space
***************************************************************************************************************************************************
*
*  Please check the lnk_rf430frl152h_NFC_Only.cmd file to customize how much code space is used for NDEF message ("FRAM_NDEF")
*  or for code ("FRAM_CODE").  
*
**************************************************************************************************************************************************/
/**************************************************************************************************************************************************
*   Main
***************************************************************************************************************************************************
*
* Brief :       Program entry.
*
* Param[in] :   None
*
*
* Param[out]:   None
*
* Return :
*
**************************************************************************************************************************************************/
void main()
{
WDTCTL = WDTPW + WDTHOLD;                   // Stop watchdog
// ROM RF13M module setup ** The following three lines are needed for proper RF stack operation
DS = 1;                                     // ROM variable needs to be initialized here
asm ( " CALL #0x5CDA ");                    // Call ROM function ( Initialize function pointers)
asm ( " CALL #0x5CAC ");                    // Call ROM function ( Check part configuration)

initISO15693(CLEAR_BLOCK_LOCKS);  // clear all block locks
//initISO15693(0);                  // leave block locks as they are set in FRAM
//JTAG is set to be disabled in this function call
DeviceInit();
while(1)
{
// Enter application code here...
__bis_SR_register(LPM3_bits + GIE);
}
}
/**************************************************************************************************************************************************
*  DeviceInit
***************************************************************************************************************************************************
*
* Brief : Initialize the clock system and other settings
*         Patchable function
*
* Param[in] :   parameters:  has these independent options
*                            INITIALIZE_DEVICE_CLOCK_SYSTEM - initializes the clock system
*                            POPULATE_INTERRUPT_VECTOR_IN_INITIALIZATION - populate the default interrupt vectors and recalculate their CRC
*
* Param[out]:  None
*
* Return  None
*
* Patchable :   Yes
**************************************************************************************************************************************************/
void DeviceInit(void)
{
//  P1SEL0 = 0xF0; //keep JTAG
//  P1SEL1 = 0xF0; //keep JTAG
P1SEL0 = 0x00; //no JTAG
P1SEL1 = 0x00; //no JTAG
P1DIR &= ~0xEF;
P1REN = 0;
CCSCTL0 = CCSKEY;                        // Unlock CCS
CCSCTL1 = 0;                             // do not half the clock speed
CCSCTL4 = SELA_1 + SELM_0 + SELS_0;      // Select VLO for ACLK and select HFCLK/DCO for MCLK, and SMCLK
CCSCTL5 = DIVA_2 + DIVM_1 + DIVS_1;      // Set the Dividers for ACLK (4), MCLK, and SMCLK to 1
CCSCTL6 = XTOFF;                         // Turns of the crystal if it is not being used
CCSCTL8 = ACLKREQEN + MCLKREQEN + SMCLKREQEN; //disable clocks if they are not being used
CCSCTL0_H |= 0xFF;                       // Lock CCS
return;
}

//#pragma vector = RFPMM_VECTOR
//__interrupt void RFPMM_ISR(void)
//{
//}
//
//#pragma vector = PORT1_VECTOR
//__interrupt void PORT1_ISR(void)
//{
//}
//
//#pragma vector = SD_ADC_VECTOR
//__interrupt void SD_ADC_ISR(void)
//{
//}
//
//#pragma vector = USCI_B0_VECTOR
//__interrupt void USCI_B0_ISR(void)
//{
//}
//#pragma CODE_SECTION(RF13M_ISR, ".fram_driver_code")  // comment this line for using ROM's RF13M ISR, uncomment next one, see .cmd file for details
#pragma CODE_SECTION(RF13M_ISR, ".rf13m_rom_isr")       // comment this line for creating a custom RF13M ISR that will exist in FRAM, bypassing ROM's, uncomment previous
#pragma vector = RF13M_VECTOR
__interrupt void RF13M_ISR(void)
{
// Right now this vector is pointing to the ROMs firmware location that runs the RF stack. 
// Entering code here will, without changing the CODE_SECTION lines
// above, will cause an error.
// Changing the code section above will cause the ROM RF stack to be bypassed.  New handler will need to be created.
}
//#pragma vector = WDT_VECTOR
//__interrupt void WDT_ISR(void)
//{
//}
//
//#pragma vector = TIMER0_A1_VECTOR
//__interrupt void TimerA1_ISR(void)
//{
//}
//
//#pragma vector = TIMER0_A0_VECTOR
//__interrupt void TimerA0_ISR(void)
//{
//}
//
//#pragma vector = UNMI_VECTOR
//__interrupt void UNMI_ISR(void)
//{
//}
//
//#pragma vector = SYSNMI_VECTOR
//__interrupt void SysNMI_ISR(void)
//{
//}
下面是NDEF.C代码:
/*
* NDEF.c
*
* RF430FRL152H NFC Only Example Project
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*    Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
*    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the
*    distribution.
*
*    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "types.h"
#include "NDEF.h"
#include "patch.h"
#include <string.h>
/* Firmware System Control Byte
*
*     Bit 0:   ISOBlockSize                0 - 4 byte,     1 - 8 byte
*     Bit 1:   Page                        0 - page 1,     1 - page 0 (Effective only for 4-byte block mode)
*     Bit 2:   ROMEUSCISupportEnabled      0 - disabled,   1 - enabled (Forced to 0 on RF430FRL153H)
*     Bit 3-5: ReservedISO
*     Bit 6:   NFCBridgeDisable            0 - enabled,    1 - disabled (see note below)
*     Bit 7:   ROMSensorSupportEnable      0 - disabled,   1 - enabled (Forced to 0 on RF430FRL154H)
*
*     NFC bridge is recommended to be disabled in this project.  Unexpected behaviour can occur,
*     trying to use it, due to the configuration being setup here.
*
*     If eUSCI host controller portion is needed along with the RF functionality, the default project
*     must be used.  That is NFC cannot be supported in that application (because the I2C/SPI host controller
*     control registers are in the same place that the NFC file needs to be).  However the rest of the FRAM
*     memory can be used for storing and reading using ISO15693.
*/
//This project is based on the RF430FRL152H.  However it will work as well on the RF430FRL154H.
//However ROM_SENSOR_SUPPORT_DISABLED (or ROMSensorSupportEnable see above for both )must be set in the firmware system control register.  This is forced automatically on the RF430FRL154H.
//This setting is needed to disable the ROM which uses block 0... as virtual registers, however this memory is needed for NDEF purposes.
#define FIRMWARE_CONTROL_ADDRESS    0xF867
#pragma RETAIN(Firmware_System_Control_Byte);
#pragma location = FIRMWARE_CONTROL_ADDRESS
//This variable needs to be kept declared and as "volatile" for the BlockLockROM_Patched function to work properly.  Assignment can be changed however.
volatile const u08_t Firmware_System_Control_Byte = ROM_SENSOR_SUPPORT_DISABLED + EROM_EUSCI_SUPPORT_DISABLED + NFC_BRIDGE_DISABLED + FOUR_BYTE_BLOCK + FIRST_ISO_PAGE; //0x7F,     // this value sets the firmware system control register
// ROM variables - DO NOT CHANGE !!!
// Declared to protect from use by compiler
/********************************************/
#pragma RETAIN(DS)
#pragma location = 0x1C00
u08_t DS;
#pragma RETAIN(RF)
#pragma location = 0x1C6A
const u08_t RF;
#pragma RETAIN(NRX)
#pragma location = 0x1CA4 //rx
const u08_t NRX[34];
#pragma RETAIN(NTX)
#pragma location = 0x1CC6 //tx
const u08_t NTX[33];
#pragma RETAIN(EL)
#pragma location = 0x1CF2
const u08_t EL;
#pragma RETAIN(PF)
#pragma location = 0x1C0A
const u16_t PF[48];
/********************************************/
/*
* This is an NDEF message: www.ti.com
* This can be made longer and edited as necessary.  However it is limited to the first page (about 968 bytes),
* the second page is mainly used for patch firmware, but can be read over NFC as well, with proper commands.
*/
#define NDEF_START_ADDRESS  0xF868
#pragma RETAIN(NFC_NDEF_Message);
#pragma location = NDEF_START_ADDRESS;                                                                  // the location of the address
const u08_t NFC_NDEF_Message[23] = {
// Block 0
0xE1,       // NDEF Magic Number
0x40,       // Version Number, read/write access conditions
0x79,  //0x7E,      // 1008 bytes / 8 = 126 blocks
0x00,//0x04,//8 byte extended memory //0x00,        // does not support read multiple blocks (limited to only 3 blocks)
// Block 1
0x03,       // NDEF Message present
0x0D,       // Length , 11 bytes-> payload of 7, pauload of 18 is 22 byte length
0xD1,       // Record header
0x01,       // type length
// Block 2
0x09,       // Payload length
0x55,       // Record Type U (URI)
0x01,       // URI header identifier
0x7A,       // 'z'
0x74,       // 't'
// Block 3
0x69,       // 'i'
0x2E,       // '.'
0x63,       // 'c'
0x64,       // 'd'
0x6F,       // 'o'
// Block 4
0x6D,       // 'm'
0xFE,       // TLV terminator
0x00,       // Empty don't care
0x00        // Empty don't care
};
/**************************************************************************************************************************************************
*  initISO15693
***************************************************************************************************************************************************
*
* Brief : Initializes the RF Stack
*
* Param[in] :   parameter - the configuration to setup the ISO15693 (option to clear the lock blocks)
*
* Param[out]:   None
*
* Return        None
**************************************************************************************************************************************************/
void initISO15693(u16_t parameters )
{
RF13MCTL |= RF13MTXEN + RF13MRXEN + RF13MRFTOEN;  // set up rx and tx functionality on RF13M module
// enable interrupts  ** Do not change the following two lines, needed for proper RF stack operatoin
RF13MINT |= RF13MRXIE + RX13MRFTOIE;              // enable interrupts on RX and on timeout and over and under flow checking
if (parameters & CLEAR_BLOCK_LOCKS )
{
memset ((u08_t *) FRAM_LOCK_BLOCKS, 0xFF, FRAM_LOCK_BLOCK_AREA_SIZE);     //block is locked with a zero bit, clears FRAM and RAM lock blocks
}
//  BlockLockAPI(3, LOCK_BLOCK);  //Test this API
//
//  BlockLockAPI(3, CHECK_LOCK);  //Test this API
}
/**************************************************************************************************************************************************
*  BlockLockAPI
***************************************************************************************************************************************************
*
* Brief : Locks a block either in FRAM or in RAM.
*
* Param[in] :   block - The block to lock.  In 4-byte mode this will lock two blocks and depends on the page selected.
*
* Param[out]:   None
*
* Return        None
**************************************************************************************************************************************************/
u16_t BlockLockAPI(u16_t block, u08_t checkLock)
{
u16_t locked;
locked = BlockLockROM_Patched(block, checkLock );
return locked;
}

这里是NDEF.h

/*
* NDEF.h
*
* RF430FRL152H NFC Only Example Project
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*    Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
*    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the
*    distribution.
*
*    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <rf430frl152h.h>
#include "types.h"
#ifndef NDEF_H
#define NDEF_H
//*****************************FUNCTION PROTOTYPES********************************/
void initISO15693(u16_t parameters );
u16_t BlockLockAPI(u16_t block, u08_t checkLock);
extern u08_t DS;
#define CLEAR_BLOCK_LOCKS                               BIT3
#define FRAM_LOCK_BLOCK_AREA_SIZE                       38
#define FRAM_LOCK_BLOCKS                                0xF840  //Address of ISO15693 lock blocks

#define ROM_EUSCI_SUPPORT_ENABLED       BIT2
#define EROM_EUSCI_SUPPORT_DISABLED     0
#define ROM_SENSOR_SUPPORT_ENABLED      BIT7
#define ROM_SENSOR_SUPPORT_DISABLED     0
#define NFC_BRIDGE_DISABLED             BIT6
#define NFC_BRIDGE_ENABLED              0
#define EIGHT_BYTE_BLOCK                BIT0
#define FOUR_BYTE_BLOCK_MASK            BIT0
#define FOUR_BYTE_BLOCK                 0
#define FIRST_ISO_PAGE_MASK             BIT1
#define FIRST_ISO_PAGE                  BIT1
#define SECOND_ISO_PAGE                 0
#define FRAM_BLOCKS_8                   0xF3

#define CHECK_LOCK                  1
#define LOCK_BLOCK                  0
#define LOCKED_FLAG                 BIT0
#endif

这里是patch.h

/*
* Patch.h
*
* RF430FRL152H NFC Only Example Project
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*    Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
*    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the
*    distribution.
*
*    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "types.h"
#ifndef PATCH_H
#define PATCH_H

//****Patch functions********************************************************************/
void GetSystemInfo_Patched();
void GetMultipleBlockSecurityStatus_Patched();
u16_t BlockLockROM_Patched(u16_t blockNumber , u08_t checkLock);
void userCustomCommand();
typedef void(*DriverFunction)(void);
//------------------------------------------------------------------------------
// Driver section
//------------------------------------------------------------------------------
extern volatile const u08_t Firmware_System_Control_Byte;
#define CRC_LENGTH_IN_BUFFER          2  // the CRC bytes take 2 bytes in the packet
#define DATA_IN_LENGTH                1  // only 1 byte of data in expected

#define DRIVER_TABLE_START              0xFFCE                  // starting address for driver table
#define DRIVER_TABLE_KEY                0xCECE                  // identifier indicating start and end of driver table
#define BLOCK_LOCK_ID                   0x2600                  // Block Lock Code for ROM
#define GET_SYSTEM_INFO_ID              0x002B                  // Get System Info ISO15693 command ID
#define GET_MUL_BLCK_SEC_STATUS_ID      0x002C                  // Get Multiple Block Security Status ISO15693 command ID
#define USER_CUSTOM_COMMAND_ID          0x00AA                  // user custom command, range from A0 - D0
#define NUMBER_OF_DRIVER_FUNCTIONS      4                       // the amount of patched functions
//------------------------------------------------------------------------------
#define CUSTOM_COMMAND         (DRIVER_TABLE_START-2)
#define CUSTOM_COMMAND_ADDR    (DRIVER_TABLE_START-4)
#define GET_SYSTEM_INFO_COMMAND (DRIVER_TABLE_START-6)                  // DIGITAL_SENSOR_DRIVER_ID, see below
#define GET_SYSTEM_INFO_ADDR    (DRIVER_TABLE_START-8)
#define GET_MULTIPLE_BLOCK_SECURITY_STATUS_COMMAND (DRIVER_TABLE_START-10)                      // INIT_DIGITAL_SENSOR_DRIVER_ID, see below
#define GET_MULTIPLE_BLOCK_SECURITY_STATUS_ADDR    (DRIVER_TABLE_START-12)
#define BLOCK_LOCK_ROM_COMMAND (DRIVER_TABLE_START-14)                      // INIT_DIGITAL_SENSOR_DRIVER_ID, see below
#define BLOCK_LOCK_ROM_ADDR    (DRIVER_TABLE_START-16)
#define DRIVER_TABLE_END  (DRIVER_TABLE_START-2-(NUMBER_OF_DRIVER_FUNCTIONS*4))
#endif

你问了两个截然不同且不相关的问题——通常最好是单独提出问题。

NFC_NDEF_Message:

以下代码:

#define NDEF_START_ADDRESS  0xF868
#pragma RETAIN(NFC_NDEF_Message);
#pragma location = NDEF_START_ADDRESS;                                                                  // the location of the address
const u08_t NFC_NDEF_Message[23] = {

的意思是:

在地址0xF868处找到NFC_NDEF_Message,并且不允许链接器删除数据对象,即使没有代码显式引用它。

要将0xF868处的数据更改为0xF87F,只需更改NDEF.c中的源。#pragma指令将确保NFC_NDEF_Message存储在该位置。

关于initISO15693()如何被称为:

initISO15693()具有外部链接并且在NDEF.h中声明为

预处理器#include是NDEF.h时,编译器使用声明表示

"这些符号存在于其他模块中,可以由稍后的链接器解析">

编译器将未解析链接占位符放在目标代码中。然后,源NDEFS.c被单独编译,符号initISO15693等在其引用实际数据实例和代码的目标代码中创建。

链接器然后将两个编译的对象模块(与项目构建和库中的任何其他模块以及运行时启动代码一起)组合在一起。在此组合过程中,未解析的链接与其他模块和库中相应的具体实例进行匹配。

这也是您如何将自己的代码分解为单独编译的模块。对于任何重要的应用程序,您都希望这样做。

查看NDEFS.h头文件或任何其他头文件,包括标准库头文件,看看这些声明是如何做出的。头文件(通常)不包含库代码或数据对象,它们通常只包含声明或存在于其他地方的代码/数据,供链接器解析。

构建可执行文件(至少)有三个阶段:
  1. 预处理:用包含的文件内容替换#include,用它们的#define'ed文本替换宏,根据#if等删除代码。
  2. 编译:将单个预处理的源模块转换为本机机器码对象模块,带有无法解析的外部代码/数据链接。
  3. 链接:从单个编译和库中组合对象模块,解析任何未解析的链接。

理解这些步骤(通常被使用诸如CCS之类的IDE隐藏或模糊)将帮助您更好地理解如何在出现问题时解决问题;例如"未定义符号";是一个编译错误(您没有声明符号或包含必需的头文件),而"未解析的符号";是一个链接器错误(您没有将所需的对象模块或库添加到构建中-并且反过来可能没有将源代码添加到项目中)。

相关内容

  • 没有找到相关文章

最新更新