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
Header (.h) and Source (.c) files
Moderators: TomKerekes, dynomotion
-
- Posts: 59
- Joined: Sun Aug 21, 2022 11:22 pm
Re: Header (.h) and Source (.c) files
Here is an example of what I have implemented:
Program to be executed when the init button is pressed:
InitConfigButtonAction.c
Header file with defines and function declarations:
InitConfig.h
Source file with function implementation:
When I try to execute the Init button I get the following error:
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();
}
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 */
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);
}
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Header (.h) and Source (.c) files
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.
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.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 59
- Joined: Sun Aug 21, 2022 11:22 pm
Re: Header (.h) and Source (.c) files
Hello Tom,
Alright, could you give me some examples of how to do this using batch files?
Sincerely,
Guilherme
Alright, could you give me some examples of how to do this using batch files?
Sincerely,
Guilherme
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Header (.h) and Source (.c) files
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.
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.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 59
- Joined: Sun Aug 21, 2022 11:22 pm
Re: Header (.h) and Source (.c) files
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
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
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: Header (.h) and Source (.c) files
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.
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.
- Attachments
-
- lnkThread2.cmd.txt
- (966 Bytes) Downloaded 82 times
-
- File2.c
- (115 Bytes) Downloaded 91 times
-
- File2.h
- (24 Bytes) Downloaded 84 times
-
- MainFile1.c
- (114 Bytes) Downloaded 81 times
-
- LinkMainFile1File2.lkf.txt
- (95 Bytes) Downloaded 91 times
-
- MakeMainFile1File2Thread2.bat.txt
- (346 Bytes) Downloaded 90 times
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.