Question: How to Link External C files to a PSoC Designer Project with HiTech compiler?
-To link the external files located outside the project directory, to the PSoC Designer project, Local.mk file has to be edited.
The Sample project has been attached here which has been compiled correctly in PD5.1 with HiTech compiler. By adding following lines to local.mk file, an external c file has been linked. To open local.mk file, click on Project -> "Open Local.mk for this Project". Add the following lines to it.
obj/%.p1 : C:/ExtFile/%.c project.mk
echo $(call correct_path,$<)
$(CCMD) $(CFLAGS) $(CDEFINES) $(INCLUDEFLAGS) $(DEFAULTCFLAGS) -O$@ $(call correct_path,$<)
There are some important points to note:
-There is a Tab(Not spaces) at the start of lines "echo ...." and " $(CCMD)...". This is important, if you copy and paste these lines to the local.mk file.
-You need to declare the functions which are defined in external C file at the top of your main code. Otherwise the compiler throws a warning.
-You do not need to add any "include" statements to your main code. Also, if you are using .h or include files located in an external directory, this process would have to be modified because the builder will not be able to find the files.
-These lines added to local.mk file will only work for HiTech compiler and not for Imagecraft compiler. There is seperate KB Article which is related to Imagecraft Compiler.
-It is better to create the project from scratch instead of saving existing project with different name and changing the compiler to HiTech. In case you get error messages.
In this example project, the external file "ExtFunctions.c" located in C:/Extfile has been linked. To test the project,
1. open the zip file attached and extract the contents.
2. Copy the 'ExtFile' folder to C: Drive.
3. Open the "Add_External_C_File" Project.
4. Generate and build the project.
5. Using CY3210 Kit, Download the code to CY8C29466-PXI device.
6. Verify whether the LED Connected to P0 blinks.