'Undefined Reference' in unit test project - c

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.

Related

fatal error: sodium.h: No such file or directory

Thank you #stark I was unaware you had to link the directory as part of #include. This part is now working though when I include.
(sodium_init() < 0)
{
printf("Sodium could not be initialized");
return 1;
}
I now receive the error "undefined reference to 'sodium_init'.
I have tried adding -lsodium to the compile command (gcc -g -lsodium file1.c file2.c file1.h -o file1.c.exe) which gives the error.
"cannot find -lsodium collect2.exe: error: ld returned 1 exit status"
Through further searching I believe I need to tell the compiler where to find -lsodium though cannot find out how.
-- below has been solved using #stark advice --
I have been trying to get the sodium library working for the last 3 days. I have followed the instillation instructions here(https://libsodium.gitbook.io/doc/installation) which all appear to have completed successfully, but still receive the error.
I then found information suggesting I have not linked Visual Studio (community edition) to the library location.
I have attempted to follow the instructions here(https://www.learncpp.com/cpp-tutorial/a2-using-libraries-with-visual-studio-2005-express/) but cannot see "VC++ Directories". I have tried several other sets of directions with the same outcome.
Is anyone able to help getting the sodium library working so I can get access to the RtlGenRandom() function?

Cause and remedy for gcc linker error on export of dll

Windows C utility program (Pname.c) being compiled and linked as a dll. I am doing this on Windows 10 using CodeBlocks and Mingw/gcc. The link step produces 1 error as follows:
Cannot export NULL_IMPORT_DESCRIPTOR: symbol not found
Cannot export SP2_IMPORT_DESCRIPTOR: symbol not found
collect2.exe: error: ld returned 1 exit status
SP2 is a dll called to handle the Windows display of error messages. These IMPORT_DESCRIPTOR parameters are in the "libPname.def" file, and my understanding is they are used in the "libPname.a" files. Other than that, I have no idea what causes the error, why the symbols are not resolved since they are in "libPname.def" file, or where to start to fix the error.
The other kicker about this is, "Pname.c" is structured the same way many other programs are structured and the others link and run just fine. I have never seen this error before.

fatal error: stdarg.h: No such file or directory when compiling wine, but the file exists

Following this documentation i had attempted to compile wine with --enable-win64 , however i was met with 4 errors all complaining about "stdarg.h" not existing :
/usr/lib/gcc/x86_64-w64-mingw32/9.3-win32/include/stdarg.h:1:15: fatal
error: stdarg.h: No such file or directory
1 | #include_next <stdarg.h>
I checked with a file explorer and sure enough it does exist, so what gives? I have googled this error to the ends of the earth but i cannot find any instance of anyone having this issue while attempting to compile wine.
If additional information is needed i will be happy to provide it, the full log is here
EDIT: Going off of Gerhardh and WENDYN's comments, the issue seems to be linked to the first line of stdarg.h which is "#include_next <stdarg.h>", which apparently includes the next file with the same header name, and i most likely am missing that "next" header.
Completely shooting in the dark but i commented out #include_next <stdarg.h> on the first line of the file, it seems to have compiled fine, tomorrow i will use the build extensively to see if any problems arise, however i would not call this a solution as i had to edit the header with root and this could potentially cause issues with the system.

Error: L6218E: Undefined symbol main (referred from __rtentry2.o)

anyone can help me?? my board is LPC1768 and the sensor is BMP180
Rebuild target 'Target 1'
compiling BMP180.c...
compiling I2C.c...
assembling startup_LPC17xx.s...
compiling system_LPC17xx.c...
compiling GPIO_LPC17xx.c...
compiling PIN_LPC17xx.c...
linking...
.\Objects\asdsa.axf: Error: L6218E: Undefined symbol main (referred from __rtentry2.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 1 error messages.
".\Objects\asdsa.axf" - 1 Error(s), 0 Warning(s).
Target not created.
I found the solution is easy, but before going deeper into the solution, keep in mind that C compilation unit (C Compiler and Assembler at least) compiles each pure C source file after resolving necessary pre-processor directives, and generates a relocatable object file as a result of compilation.
After the compilation unit does its job, there is another unit that is responsible for combining individually every source file that is compiled successfully into the relocatable form of one big object file for all. This unit is called Linker and the operation is called Linking
A very important feature in relocatable object file is that what is called variable, function will be noted as symbol so far. The linker has to solve the symbols, defining what is originally defined in an object file, reference what is being used in another to their original object file.
After this motivation, now we can call main() function as main() symbol.
I Found that the problem is because the source file that contains the main() function was not compiled. As a result, there is no a relocatable object file that contains the symbol corresponding to main() function. Hence, the compiler is complaining: you asked me to use (reference) a symbol you guaranteed to be found (defined) in another file but I found no such symbol!
The solution:
For Kiel IDE, to queue a source file for a compilation; you gotta shortlist it in the category "Source Group",by clicking right, either adding new files to group, or existing files to group. It will result in something like the following figure:
Now we have a main function, is turned (defined) to main symbol later, and found by the linker to reference it to whatever use it in any other relocatable object files.
I solved this problem with the following steps;
Delete your old project and create new project
Choose true library from Manage Run Time Environment like so:
Configure "Options for Target" segment. Define symbol USE_STDPERIPH_DRIVER and define project path like so:
Test your configuration. Please write the following code:
#include "stm32f10x.h" // Device header
int main() {
}
I had the same issue. The problem was that the function name in .c file had a different name with the one in the .h file, and I didn't know.
just add your c file (ex: 'main.c') to the source group (ex: 'source group 1') by expanding the target then right click on the source group, choose add existing files to group 'your source group', then choose the main.c file.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/14222.html
This should help.
Just create a dummy main() or main.c file. Linker can't find it in your pjt.
For solution only add this file C to driver folder and translate it,
Solved: This "Target Not Created" Issue was Resolved by the setting of Run Time Environment as shown in below(url) image.https://i.stack.imgur.com/kJ4IL.jpg ( consisting of CMSIS and Device supporting components in Run time environment)
{ compiling TransformFunctions.c...
linking...
Program Size: Code=768 RO-data=320 RW-data=4 ZI-data=612
FromELF: creating hex file...
".\Objects\LPC1768_B_T.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:07
}

Build throwing error "Command ... llvm-gcc-4.2 failed with exit code 1"

Here's the log from the build. This is a brand new project in Xcode 4, so the only non-regular things in it are as follows:
A .c file
A .a library
A bunch of header files
I've been playing with the build settings and searching for answers for a couple of hours now to see if it would go away, but it didn't. Any help you have would be appreciated.!
The output (click for a larger image):
You have a duplicate symbol error - your program can't have two functions called main(). Remove one of them, and you should be able to move forward.

Resources