This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: Linking error: unresolved symbols remain after moving function definitions to different source file



Tool/software: TI C/C++ Compiler

Before moving these function definitions, everything would compile fine. Now I am getting an unresolved symbols error and can't figure out why.

I moved 4 function definitions from one source file, lets say file1.c, to another source file, file2.c. I just cut and pasted these definitions, I did not make any changes at all.

I updated the corresponding header files file1.h and file2.h as well. I cut the function declarations from file1.h and pasted them into file2.h.

I then updated all other source files which previously referenced file1.h for the moved functions to instead reference file2.h.

2 out of the 4 functions that are now in file2.c cannot be found by the linker for some reason. The other 2 work fine. There aren't any noticeable differences between the 2 working and the 2 non-working functions. All 4 of these functions are pretty simple, less than 5 lines of code. Their definitions are of similar format too. 

Now if I copy the 2 non-working function definitions from file2.c and paste  them back into file1.c, everything works fine, even without updating file1.h or file2.h to reflect this change. The compiler doesn't complain about multiple definitions, even though both file1.c and file2.c contain 2 identical function definitions.

It seems as if the compiler doesn't see these 2 functions in file2.c for some reason.

I am using CCS Version: 6.1.0.00104. Please let me know if any more details are needed.

It may be worth noting that I renamed the project earlier that day as well, by going to File > Rename. I was able to compile after this though, with no problems.

Any ideas on what could be going on? Could some reference file be caching some old data that needs to be cleared?

  • No, there is no compilation cache.  Something weird is going on.

    • Does CCS properly recompile each file when you modify it?
    • Are any of these functions inline or static?
    • Have the compiler keep the assembly file (option --keep_asm).  Do the missing functions appear in the assembly file?

  • All 4 of the functions are inline. After you mentioned that, I tried removing inline and everything seems to work fine now.

    Why was this an issue? Why were 2 of the inlined functions fine, but the other 2 weren't?

    edit: I'm thinking that the 2 buggy functions were ones that were actually being inlined, since they are used so often, while the other 2 functions that worked fine and were also using the inline keyword, were not actually being inlined since they aren't used that often? But this aside, why would all 4 of the functions link fine in the first place, while they were still in file1.c?

  • Most likely all of the callers of the 2 "missing" functions are in file1.c. When the functions are actually present in file1.c, they get inlined without issue. However, when you moved them to file2.c, they cannot be inlined in file1.c, so you get a function call from file1.c. For whatever reason (perhaps the functions are static?) the definitions in file2.c did not end up in the object file (perhaps they are unused in file2.c?), so the calls end up unresolved at link time.
  • The 2 missing functions aren't called by file1.c at all, but they are actually called by file 2.c.

    I didn't really mention that there are other source files, which also do call the missing functions (these functions aren't static also).

    I'm thinking that when the "missing" functions were in file1.c, other files were able to get externally linked to those functions, but now that the missing functions are in file2.c, they are being internally linked only?
  • Perhaps, but I couldn't tell you for sure without looking at all of the source code.
  • That ended up being the exact problem. While keeping the inline keyword for the "missing" function definitions in file2.c, I removed the function calls of the "missing" functions within file2.c, and the compiler stopped complaining. Thanks for the help!