0
\$\begingroup\$

I'm having trouble getting a simple blinky project working using the on-board LED's on the TIVA TM4C123G evaluation board. I am using the header files from the driver libraries so I don't have to write directly to the registers as much anymore. However my problem is that I am getting a compilation error saying (cannot open source input file "header file names here": No such file or directory). I am unsure what I am doing wrong. Is how I have saved the header files and included them correct? What is causing this error message?

By the way if I comment out the first include directive, I get the same error messages for the header files hw_memmap and gpio. I have copy and pasted the header files from the driver library folder into the folder for this project called Code1.

Below is my C file containing the main program:

#include "inc/tm4c123gh6pm.h"
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/gpio.h"

#define RED_LED     GPIO_PIN_1
#define BLUE_LED    GPIO_PIN_2
#define GREEN_LED   GPIO_PIN_3

// The error routine that is called if the driver library encounters an error.

#ifdef DEBUG

void

__error__(char *pcFilename, uint32_t ui32Line)

{

}

#endif


int main(void)

{

    // Setup the system clock to run at 50 Mhz from PLL with crystal reference

    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

        // Unlock the Port F register.

        GPIO_PORTF_LOCK_R = 0x4C4F434B;

        // Enable the Port F commit register.

        GPIO_PORTF_CR_R = 0xFF;

        // Enable and configure the GPIO port for the LED operation.

        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED);

        // Loop Forever

     while(1)

    {

        // Turn on the LED

        GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, RED_LED);

                // Delay for a bit

        SysCtlDelay(2000000);

        // Turn on the LED

        GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED|GREEN_LED, BLUE_LED);

                // Delay for a bit

        SysCtlDelay(2000000);

    }

}

Below is a screenshot of my Keil project showing the error message for the header file and all my include files inside my C source file that contains the program:

Image of Keil project showing error message and included files

Also here is a screenshot of the header files being saved in the same location as the C source file that includes them:

Screenshot of file locations

EDIT

Peter Smith's comment solved my issue. I had the file name typed in wrong in the program so it was searching in the wrong directory for the header files.

However that issue is fixed, but when I tried compiling once again I got these 5 error messages as seen in the screenshot below. I am confused as all these functions are defined in their header files. Also this time I created a new project to see if it made a difference, hence the project name changed from Code1 to Testing. But they are virtually identical.

Screenshot of 5 new error messages

\$\endgroup\$
9
  • 2
    \$\begingroup\$ The compiler is looking for the file in the subdirectory inc below your working directory (which does not exist); remove the inc/ and retry it. \$\endgroup\$ Commented May 17, 2020 at 11:33
  • 2
    \$\begingroup\$ Or set up the include paths properly in the project. The right setting is usually quite well hidden, and different in every IDE; finding it is just one of those life skills you'll have to develop. \$\endgroup\$
    – user16324
    Commented May 17, 2020 at 13:51
  • \$\begingroup\$ @PeterSmith Yeah that was the problem, thank you. I have ran into another problem that I am unsure about. I have edited my question above. \$\endgroup\$
    – David777
    Commented May 17, 2020 at 13:59
  • 3
    \$\begingroup\$ The new one is a linker error; the compiler having found the source files, the linker can't find the objects compiled from them. Either it's supposed to compile them and doesn't (mis-configured compiler options, or in desperation try compiling them by hand), or they are pre-compiled but the library paths are mis-configured like the include paths were. Either way, see prev comment. I haven't used Keil this century, so I'm out. \$\endgroup\$
    – user16324
    Commented May 17, 2020 at 14:11
  • 2
    \$\begingroup\$ You need to add the library C files as well to your project, so that they get compiled and can be linked against when building your executable. In this case, judging by the missing symbols, the needed files are probably sysctl.c and gpio.c. But in compiling even those two, they may have their own dependencies, more C files that you need to include in your project, with their own dependencies and so on. This is why it's best to simply have the whole library present in the project. All the separate modules will be built and then be available for linking to create your final executable. \$\endgroup\$ Commented May 18, 2020 at 0:04

1 Answer 1

1
\$\begingroup\$

First, you should always add all the library files to the project. Everything. Headers and source files included. In fact, it would be best if you started from a new project and installed the Device Family Pack as instructed. Follow Keil and Tiva instructions or any online tutorials to the letter. Only after you've successfully built an application using the standard procedures, to do basic stuff like blink an LED, should you then begin tinkering with the build process, as you're doing. For now, you do not know enough yet or have a reference "working" setup.

Second, the include errors you're getting are likely because you haven't configured your include paths. Based on your image, you did not maintain the original library structure but instead copied the header files directly to the same folder as your main.c, thus those headers are found automatically when compiling main.c but can't be seen by any other source file that isn't in that folder, especially when they're looking for inc/hw_memmap.h for instance. Do not mistake the internal Keil IDE folder structure for the actual folder structure on disk; these two have little to do with each other.

You need to inform Keil (as with most other IDEs) about where to look for header files.

  • Delete those library headers that you have copied directly to main.c's folder. main.c should be the only file with code left in that folder.
  • I think I can see you already have the Device Family Pack included in your project. Clicking the Device item on the left should show all the library source files. If it doesn't, then add the library, following Keil instructions. Probably best done from a new project, as I said earlier.
  • This answer here explains how to add the include paths to your project settings. This step is necessary for every project you create. The important paths you need to add are: inc/ and driverlib/. Supply the absolute paths, i.e. C:/..., to be sure.

If you try to build now and get the Undefined symbol linker errors again, it means you still don't have those library source files present in your project.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the answer. You guys have pointed out my mistake, which was in fact not the files not in the correct location. I copied the driver library download folder to another place which caused the problem. I included the original folder using the absolute path and found them all ok. Thanks everyone for their help. \$\endgroup\$
    – David777
    Commented May 21, 2020 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.