Linking errors when compiling using Microchip C30 compiler for Openpicus - c

I am compiling a project with lot of external libraries. The project has some warnings , but i believe that it should not hamper the creation of the .hex file. So when i compile the project I get a list of linking errors.
Compiling C:\liblwm2m\Libs\ExternalLib\heap.s
* Total program memory used (bytes): 0x28ef3 (167667) 64%
* Total data memory used (bytes): 0x360a (13834) 84%
x_object_device.o(.text+0x688):C:\liblwm2m\Libs\ExternalLib\object_device.c: undefined reference to `strdup'
x_object_device.o(.text+0x68a):C:\liblwm2m\Libs\ExternalLib\object_device.c: undefined reference to `strdup'
x_object_device.o(.text+0x6b6):C:\liblwm2m\Libs\ExternalLib\object_device.c: undefined reference to `strdup'
x_object_device.o(.text+0x6b8):C:\liblwm2m\Libs\ExternalLib\object_device.c: undefined reference to `strdup'
x_object_device.o(.text+0x6e4):C:\liblwm2m\Libs\ExternalLib\object_device.c: undefined reference to `strdup'
x_object_device.o(.text+0x6e6):C:\liblwm2m\Libs\ExternalLib\object_device.c: more undefined references to `strdup' follow
x_observe.o(.text+0x3c2):C:\liblwm2m\Libs\ExternalLib\observe.c: undefined reference to `object_read'
x_observe.o(.text+0x3c4):C:\liblwm2m\Libs\ExternalLib\observe.c: undefined reference to `object_read'
x_liblwm2m.o(.text+0x86):C:\liblwm2m\Libs\ExternalLib\liblwm2m.c: undefined reference to `strdup'
x_liblwm2m.o(.text+0x88):C:\liblwm2m\Libs\ExternalLib\liblwm2m.c: undefined reference to `strdup'
x_management.o(.text+0x48):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_read'
x_management.o(.text+0x4a):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_read'
x_management.o(.text+0xa6):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_create'
x_management.o(.text+0xa8):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_create'
x_management.o(.text+0x154):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_isInstanceNew'
x_management.o(.text+0x156):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_isInstanceNew'
x_management.o(.text+0x16e):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_create'
x_management.o(.text+0x170):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_create'
x_management.o(.text+0x188):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_write'
x_management.o(.text+0x18a):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_write'
x_management.o(.text+0x1a2):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_execute'
x_management.o(.text+0x1a4):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_execute'
x_management.o(.text+0x1da):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_write'
x_management.o(.text+0x1dc):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_write'
x_management.o(.text+0x208):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_delete'
x_management.o(.text+0x20a):C:\liblwm2m\Libs\ExternalLib\management.c: undefined reference to `object_delete'
x_registration.o(.text+0x8c):C:\liblwm2m\Libs\ExternalLib\registration.c: undefined reference to `prv_getRegisterPayload'
x_registration.o(.text+0x8e):C:\liblwm2m\Libs\ExternalLib\registration.c: undefined reference to `prv_getRegisterPayload'
C:\Program Files\Microchip\MPLAB C30\bin\bin/pic30-coff-bin2hex.exe: a.cof could not be opened.
The system cannot find the file specified.
---------------------------------- COMPILING ERROR ---------------------------------------
Here the strdup function is in which is supported by openpicus and i have also declared it. What surprises me is that the program compiles correctly but throws linking errors. Any thoughts about this ?
Thanks in advance

These are the errors in the code
undefined reference to strdup'
undefined reference toobject_read'
undefined reference to object_create'
undefined reference toobject_isInstanceNew'
undefined reference to object_create'
undefined reference toobject_write'
undefined reference to object_execute'
undefined reference toobject_write'
undefined reference to object_delete'
undefined reference toprv_getRegisterPayload'
P.S. these are not warnings!!
The error indicates that there is no definition of the functions "strdup", ... , "prv_getRegisterPayload". The linker does not find the references to these routines, and it terminates with a link time error. No linking means no hex file produced, that is the standard behavior of all toolchains.
Check the libraries that you have attached to the project. Add the libraries that have references/definitions for these routines, and the code should then build fine.
A pseudo code that will produce a similar error is as:
extern void parabola ();
int main(void)
{
parabola (); // ERROR here "undefined reference to `parabola'
}
-- Where is the definition of the function parabola? Shouldn't it be
void parabola ()
{}
int main(void)
{
parabola (); // Builds like magic
}

Related

why is the error of Undefined symbol detected in semantic analysis?

According to me ,An undefined symbol should be detected in parsing phase since after token is made in the lexical phase , then its type is undefined and if we try to assign a value to that undefined symbol , then how is the parse tree constructed without any error ?
int a;
b=19;
Here , the for symbol b , token has already been generated by the lexical analyser and value is as well associated with it , so what is done in the parsing phase due to which the undefined symbol is not detected in this phase ?

why this is giving an error? [duplicate]

simple problem:
given the following program:
#include <stdio.h>
inline void addEmUp(int a, int b, int * result)
{
if (result) {
*result = a+b;
}
}
int main(int argc, const char * argv[])
{
int i;
addEmUp(1, 2, &i);
return 0;
}
I get a linker error...
Undefined symbols for architecture x86_64:
_addEmUp", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
seems as though it doesn't bother to compile it.
it shouldn't need to be static, I wouldn't think, based on what I have read in:
Linker error inline function (as this is in a different object, and dealing with 2 definitions rather than zero)
This is a related link, but it is c++ and I don't think it is good practice in std C to put code in the header:inline function linker error
compiler info:
cc --version
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
compilation example:
# cc main.c
Undefined symbols for architecture x86_64:
"_addEmUp", referenced from:
_main in main-sq3kr4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocatio
Paragraph 7 of section 6.7.4 says:
Any function with internal linkage can be an inline function. For a function with external linkage, the following restrictions apply: If a function is declared with an inline function specifier, then it shall also be defined in the same translation unit. If all of the file scope declarations for a function in a translation unit include the inline function specifier without extern, then the definition in that translation unit is an inline definition. An inline definition does not provide an external definition for the function, and does not forbid an external definition in another translation unit. An inline definition provides an alternative to an external definition, which a translator may use to implement any call to the function in the same translation unit. It is unspecified whether a call to the function uses the inline definition or the external definition.
Your file does not contain an external definition of addEmUp, and the compiler chose to use the external definition in the call in main.
Provide an external definition, or declare it as static inline.
Try adding the "-O" option to your compiler command. Inlining is turned on only when optimization is enabled.
The program causes undefined behaviour (no diagnostic required) due to 6.9/5, sometimes informally called the "one definition rule":
If an identifier declared with external linkage is used in an expression (other than as part of the operand of a sizeof or _Alignof operator whose result is an integer constant), somewhere in the entire program there shall be exactly one external definition for the identifier; otherwise, there shall be no more than one.
Your program uses the identifier addEmUp while providing no external definition for it. (As mentioned already, "An inline definition does not provide an external definition for the function").
We do not need to start talking about which definition a function call calls etc. etc. The reason for ODR violations being undefined with no diagnostic required is to make it easier on the compiler writer; if this code required a diagnostic then the compiler would have to do a pass with inline optimization disabled to check for the existence of the external definition, which is a waste of time really.

Disabling OpenMP in compiler options produce tons of reference errors

I have a project in C and I need to measure program performance in parallel and sequential mode.
Program is parallelized with openmp.
If I compile my program with -openmp flag everything is fine.
But if I replace -openmp with -openmp-stubs I get tons of reference errors:
ccc.c:614: undefined reference to `__kmpc_for_static_init_4'
ccc.c:614: undefined reference to `__kmpc_for_static_fini'
ccc.c:624: undefined reference to `__kmpc_barrier'
build/liblcthw.a(ccc.o): In function `deusv2v_dbg':
ccc.c:632: undefined reference to `__kmpc_global_thread_num'
ccc.c:632: undefined reference to `__kmpc_ok_to_fork'
ccc.c:632: undefined reference to `__kmpc_fork_call'
ccc.c:632: undefined reference to `__kmpc_serialized_parallel'
ccc.c:632: undefined reference to `__kmpc_end_serialized_parallel'
build/liblcthw.a(ccc.o): In function `L_deusv2v_dbg_632__par_region0_2_862':
ccc.c:636: undefined reference to `__kmpc_for_static_init_4'
ccc.c:636: undefined reference to `__kmpc_for_static_fini'
ccc.c:646: undefined reference to `__kmpc_barrier'
build/liblcthw.a(ccc.o): In function `seusv2v_dbg':
ccc.c:654: undefined reference to `__kmpc_global_thread_num'
ccc.c:654: undefined reference to `__kmpc_ok_to_fork'
ccc.c:654: undefined reference to `__kmpc_fork_call'
ccc.c:654: undefined reference to `__kmpc_serialized_parallel'
ccc.c:654: undefined reference to `__kmpc_end_serialized_parallel'
build/liblcthw.a(ccc.o): In function `L_seusv2v_dbg_654__par_region0_2_954':
ccc.c:658: undefined reference to `__kmpc_for_static_init_4'
ccc.c:658: undefined reference to `__kmpc_for_static_fini'
ccc.c:668: undefined reference to `__kmpc_barrier'
Compiler: icc version 13.1.3 (gcc version 4.4.6 compatibility)
What I'm doing wrong? Is it possible to temporary disable openmp in other way?
I use omp_get_wtime to measure performance time so I can't just disable OpenMP at all.

Enabling UBIFS in U-BOOT

I am attempting to enable UBIFS support into u-boot but have encountered several undefined reference errors when compiling. In my board configuration, I have enabled the following:
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_CMD_UBI
#define CONFIG_RBTREE
#define CONFIG_CMD_UBIFS
#define CONFIG_LZO
And get the following undefined reference errors when compiling:
uboot/fs/ubifs/lpt_commit.c:1232: undefined reference to dbg_chk_lpt_free_spc
uboot/fs/ubifs/lpt_commit.c:1235: undefined reference to `dbg_check_ltab'
fs/built-in.o: In function `layout_cnodes':
uboot/fs/ubifs/lpt_commit.c:322: undefined reference to `ubifs_dump_lpt_lebs'
fs/built-in.o: In function `ubifs_add_bud_to_log':
uboot/fs/ubifs/log.c:194: undefined reference to `ubifs_commit_required'
uboot/fs/ubifs/log.c:225: undefined reference to `ubifs_request_bg_commit'
uboot/fs/ubifs/log.c:265: undefined reference to `ubifs_write_node'
fs/built-in.o: In function `ubifs_log_end_commit':
uboot/fs/ubifs/log.c:479: undefined reference to `ubifs_write_master'
fs/built-in.o: In function `do_write_orph_node':
uboot/fs/ubifs/orphan.c:248: undefined reference to `ubifs_write_node'
dbg_chk_lpt_free_spc, db_check-ltab, ubifs_dump_lpt_lebs, ubifs_write_node, and ubifs_write_master are"ifdef'd" out (#ifndef __UBOOT__ but...obviously __UBOOT__ is defined).
With a quick grep, ubifs_commit_required, ubifs_request_bg_commit are completely missing implementations.
Does u-boot not support UBIFS entirely, or is it currently broken? (Using 2016.07 release). Or am I perhaps missing a step...
UBIFS was indeed broken in the mainline for several architectures. A proposed patch can be found in the pipemail at http://lists.denx.de/pipermail/u-boot/2016-September/265474.html, but it hasn't been approved yet. The patch applied without issues and I can now compile, though whether the filesystem works with it remains to be seen...

What does this `ld` error ("undefined reference") mean?

What does this error mean?
/tmp/ccevEqoI.o: In function `main':
funcptr.c:(.text+0x61): undefined reference to `AddALL'
collect2: ld returned 1 exit status
I'm trying to write a function which adds all the integers up to the limit
entered by the user.
Transcribed 'answer' which is a comment from the OP:
I wrote a program that would add all the integers upto the limit Specified. For that I had to write a function. So I made a function called 'AddAll' but when I called it from my program I called it as 'AddALL'.
Note: C is case sensitive. Eventually when I changed the name of the function where I was calling it. It compiled perfectly :)
Just thought that this piece of info would be useful to beginners.
It means that the linker (that is called ld in gcc) did not found the symbol AddALL in the specified object files. Basically, there is no body for that function or it's a variable declared as extern with no definition.
It tells you that the definition for the function 'AddALL' could not be found. Make sure that you include the object file that contains 'AddALL' when you compile/link.

Resources