0

I am using TinyEmbeddedTest and VisualGDB in Visual Studio 2015, and attempting to create a unit test project as part of my solution. My main project builds and runs fine, but the unit test project is getting linker errors and will not build.

The tests are in a source file, ADCTests.cpp, which has

#include “ADC.c”

Which I believe is appropriate for TinyEmbeddedTest.

The file ADC.c contains the following include lines:

#include “ADC.h”
#include “fault.h”

The errors are thrown in ADC.c, on the following statements:

if (status == SUCCESS)
{
Fault_Clear(FAULT_ADC_FAILURE);
rawADCValue = HAL_ADC_GetValue(hADC);
}
else
{
Fault_Set(FAULT_ADC_FAILURE);
rawADCValue = 0u;
}

The errors are:

undefined reference to ‘Fault_Clear’

undefined reference to ‘Fault_Set’

From this I can see that the header file, fault.h, where these functions are declared, is accessible to the toolchain, because otherwise there would be a compilation error, but the source file. fault.c, where these functions are defined, does not seem to be accessible. Both of these files are in the same project.

I do not get these errors when running my main project, only in the unit test project.

I thought that perhaps the answer might lie in the project linker settings, and so I added a line to the Linker->[Additional Inputs] as follows:

C:\Development\myProject\VisualGDB\Debug\Src

I assumed that this would give the linker access to the .o files, created by the compiler. Unfortunately this created a new problem. The build now fails without any error messages. The list of build messages simply says

Build failed: arm-none-eabi-g++.exe exited with code 1 Id returned 1 exit status

and when I look at the log, it says

c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: cannot find C:/Development/myProject/VisualGDB/Debug/Src: Permission denied

Interestingly, that last path is a hyperlink, and when I click on it, I get an error dialog box

Failed to open ‘C:\SysGCC\arm-eabi\Development\myProject\VisualGDB\Debug\Src’

This is especially odd, because I know that path does not exist, and that is definitely not the path that I entered in the Linker settings.

Any guidance would be much appreciated.

Smoggie Tom
  • 306
  • 4
  • 12
  • This smells like a header file without header guards: `#ifndef HEADER_H #define HEADER_H .... #endif`. – Lundin Mar 19 '21 at 13:45
  • Please don't `#include` source files. Change your build scripts or project so that the tests are built with and linked to the other source files (or the object files created from those source files). – Some programmer dude Mar 19 '21 at 13:47
  • @Lundin : Undefined reference is a linker error, header guards prevent duplicate references in _compilation_. – Clifford Mar 20 '21 at 07:51
  • Something the VisualGDB plug-in is doing maybe - plug-in rather then project properties perhaps?. The project and solution files in VS are XML and can be edited as plain text. The simplest way of solving these problems is often to edit the XML files to correct any erroneous paths. Often inspection of the XML will reveal where in the project the properties the error has arisen. Add ADC.h as a project module - do not `#include` it. ADCTests.cpp should include ADC.h - I hope your embedded system is not built that way too? – Clifford Mar 20 '21 at 07:58
  • @Clifford If skip header guards and therefore end up with multiple instances of the same function created by several different translation units, then you usually get linker errors. – Lundin Mar 22 '21 at 08:26
  • @Lundin that would only happen if the headers contained definitive rather than declarative code; like for example including ADC.c in multiple translation units. The appropriate solution there is not to add include guards to ADC.c, but to separately compile and link it. Either way what you describe is "multiply defined" not "undefined". It happens when you define the same symbol more than once, not when you omit include guards in a _declaritive_ header - that results in "multiple declaration" and is a _compiler_ not a _linker error_. – Clifford Mar 22 '21 at 09:10

0 Answers0