1

I have a folder components in my project which has another folder fico in which there is a file I want to use le_helper_stub_local.h (components -> fico -> file I want to use). Then I have another folder positioning which has two folders: platform and posDaemon. I am working with a file inside posDaemon and I want to include in this file le_helper_stub_local.h.

I used the following:

#include "../../ficoStub/le_helper_stub_local.h"

but when I compile I have an error of undefined reference to the functions I am using from inside le_helper_stub_local.h What am I doing wrong? sorry if it sounds like a beginner question but I don´t really use C.

the code for le_helper_stub_local.h:

#ifndef LEGATO_STUB_LOCAL_INCLUDE_GUARD
#define LEGATO_STUB_LOCAL_INCLUDE_GUARD

#include "legato.h"

FILE * Stub_openStream(char *pathIn);
void Stub_writeHeader(FILE* fp, char *functionName);
void Stub_writeParam (FILE* fp, int nParam, char *paramName, char* 
paramContent);
void Stub_writeTail(FILE* fp);
bool Stub_lookForCall(FILE* fp, int *remains);
void Stub_updateRemains(FILE *fp, int remains);

le_result_t le_helper_stub_Init
(
    void
);

#endif // LEGATO_STUB_LOCAL_INCLUDE_GUARD

this is a part of the code where I´ve included the above file: le_result_t le_gnss_GetDate ( le_gnss_SampleRef_t positionSampleRef, ///< [IN] ///< Position sample's reference.

uint16_t* yearPtr,
    ///< [OUT]
    ///< UTC Year A.D. [e.g. 2014].

uint16_t* monthPtr,
    ///< [OUT]
    ///< UTC Month into the year [range 1...12].

uint16_t* dayPtr
    ///< [OUT]
    ///< UTC Days into the month [range 1...31].
)
{

le_result_t result = LE_FAULT;

// 1. Open the output file and add/save information related to the execution.
char pathOut[] = "/stub/positioning_le_gnss_GetDate.out";
char functionName[] = "le_gnss_GetDate";

FILE * fp = Stub_openStream(pathOut);
Stub_writeHeader(fp, functionName);
Stub_writeTail(fp);
result = le_atomFile_CloseStream(fp);  

return result;

for compiling I have a script which compiles my entire project which is python and C. It´s too long to write it here. This is the error I get during complilation:

posDaemon.so: undefined reference to Stub_writeHeader' build/qemuarm/system/component/6c05f6c53a95e6505773ec507f339d0a/obj/libComponent_posDaemon.so: undefined reference toStub_writeTail' build/qemuarm/system/component/6c05f6c53a95e6505773ec507f339d0a/obj/libComponent_posDaemon.so: undefined reference to `Stub_openStream' collect2: error: ld returned 1 exit status [390/601] Linking C executable

I´ve used the le_helper_stub_local.h before in other files but I´ve never had this problem before. I also don´t think now that it´s an inclusion problem.

H.A.
  • 161
  • 1
  • 4
  • 18
  • 1
    What is the exact error message? What is the exact folder structure? Where are the functions from `le_helper_stub_local.h` implemented? Do you compile that C file too and link it in? – Maximilian Gerhardt Jan 23 '18 at 16:28
  • 3
    'undefined reference' is a linker error. So show your code and the commands used to compile and link – pm100 Jan 23 '18 at 16:28
  • 1
    Undefined reference is meaning that the problem is not with inclusion but with linking. – Eugene Sh. Jan 23 '18 at 16:28
  • Backwards relative paths should work. – Greg Schmit Jan 23 '18 at 16:28
  • I'm going to assume a `-L` path needs to be passed into the linker – Christian Gibbons Jan 23 '18 at 16:32
  • Your problem is not with the header. You fail to define whatever is missed. See https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Yunnosch Jan 23 '18 at 17:13
  • Note that [relative include paths with `..` in the names](https://stackoverflow.com/questions/597318/) are usually not a good idea. You locate headers by specifying on the command line where they're found, with an option such as `-I../../ficoStub` while the code includes `#include "le_helper_stub_local.h"`. Sometimes, you might prefer `#include "ficoStub/le_helper_stub_local.h"` in which case you'd use `-I../..` on the command line. You problem, though, is with the linker. You need to specify where the object files, or the library (or libraries) containing the object files are found. – Jonathan Leffler Jan 23 '18 at 17:16
  • Relative include path is a common method in code development, and this is a common problem that happens very often. Search stackoverflow, or try to resolve it with you means: Find the real root folder of your project, check if the file that you have really exist, by referencing to it by writing the full path in your code. The full path step is used only to debug the issue. After that, you may try to set properly your path. Read this to orient you about the reason for this error message: https://latedev.wordpress.com/2014/04/22/common-c-error-messages-2-unresolved-reference/ – VladP Jan 23 '18 at 22:59

0 Answers0