Page 1 of 1
Header (.h) and Source (.c) files
Posted: Mon Nov 07, 2022 12:17 pm
by gui_marchioro
Hello,
I would like to organize my project files using .h for function prototypes and variable declarations, and .c file to the variable definitions and the "implementation" ("executable code" to be compiled).
I have implemented this, following what is described in this link
https://riptutorial.com/c/example/3250/ ... her-c-file.
However, by trying such organization I am getting a compilation error.
Has anyone made something in this way and could make it work?
Sincerely,
Guilherme
Re: Header (.h) and Source (.c) files
Posted: Mon Nov 07, 2022 12:27 pm
by gui_marchioro
Here is an example of what I have implemented:
Program to be executed when the init button is pressed:
InitConfigButtonAction.c
Code: Select all
#include "InitConfig.h"
#include "KMotionDef.h"
// Initialization program that runs when the Init button is pressed inside KMotionCNC
main()
{
// Initializes Konnect boards
IOboardsConfig();
// Initializes KFlop and Kanalog board
InitConfig();
}
Header file with defines and function declarations:
InitConfig.h
Code: Select all
#ifndef InitConfig_h
#define InitConfig_h
#define ENABLE_ALL_AXIS_PIN 1056 // Brake enabled
#define INIT_EXECUTED_VAR 180
// Initial configuration for Axis and IOBoards
void InitConfig();
// Configure the Konnect IO boards connected with the KFLOP main board
void IOboardsConfig();
#endif /* InitConfig_h */
Source file with function implementation:
Code: Select all
#include "InitConfig.h"
#include "KMotionDef.h"
// Initial configuration for Axis and IOBoards
void InitConfig()
{
// Supressed code for example purposes
}
// Configure the Konnect IO boards connected with the KFLOP main board
void IOboardsConfig()
{
InitAux();
AddKonnect(0,&VirtualBits,VirtualBitsEx);
AddKonnect(1,VirtualBitsEx+1,VirtualBitsEx+2);
}
When I try to execute the Init button I get the following error:
Re: Header (.h) and Source (.c) files
Posted: Mon Nov 07, 2022 5:39 pm
by TomKerekes
Hi Guilherme,
The example in your reference compiles 2 files separately and then links the 2 files together.
KMotion is set up to simply compile one file and link it. So you must also include InitConfig.c in InitConfigButtonAction.c to form one .c file with everything.
There are ways to have multiple files linked together using the TI Compiler but it is somewhat complicated using batch files that you must create.
Re: Header (.h) and Source (.c) files
Posted: Mon Dec 05, 2022 11:07 am
by gui_marchioro
Hello Tom,
Alright, could you give me some examples of how to do this using batch files?
Sincerely,
Guilherme
Re: Header (.h) and Source (.c) files
Posted: Mon Dec 05, 2022 9:18 pm
by TomKerekes
Hi Guilherme,
See the folder:
C:\KMotion435h\C Programs\TI_Compiler
If you aren't familiar with invoking the Compiler, Linker, and Linker command files then just include the C file as explained earlier.
Re: Header (.h) and Source (.c) files
Posted: Thu Dec 08, 2022 3:50 pm
by gui_marchioro
Hello,
I am not familiar with the TI Compiler, but I am with compiling and linking operations like in the example from my first post, which can be found here:
https://riptutorial.com/c/example/3250/ ... her-c-file
I really would like to apply this development pattern in my project. So, I would be very grateful if you give me a simple example of using the TI compiler to compile .c files and then link them together to form a .out file.
I have already downloaded the compiler software from Texas Instruments and tested it with the example you mentioned in the previous post.
Sincerely,
Guilherme
Re: Header (.h) and Source (.c) files
Posted: Sat Dec 10, 2022 5:49 pm
by TomKerekes
Hi Guilherme,
Here is an example batch file MakeMainFile1File2Thread2.bat that will compile MainFile1.c and File2.c and link them to make a MainFile1(2).out to execute in Thread2. Copy files to the C:\KMotion435h\C Programs\TI_Compiler folder. Remove any .txt extensions.