Renesas GCC linker error with shared code

904 Views Asked by At

I'm using GCC for Renesas with Renesas's E2 Studio IDE (v.6.2.0). Not that it should matter, but I've also used Applilet3 (v.3.08.01.05) to generate board support files and peripheral drivers.

When I attempt to build, I get the following errors...

'Invoking Linker'
rl78-elf-gcc (......object files and flags.......)
./src/r_main.o: In function `main':

<path_to_git_repo_dir>\src\<project_name>\HardwareDebug/../src/r_main.c:86: undefined reference to `_common_lib_a_init'
<path_to_git_repo_dir>\src\<project_name>\HardwareDebug/../src/r_main.c:89: undefined reference to `_common_lib_b_init'

collect2.exe: error: ld returned 1 exit status
makefile:67: recipe for target 'my_project.elf' failed
make: *** [my_project.elf] Error 1

Project Setup

I have some source code shared between projects in a "lib" folder. In main() I call some initialize functions for these "libraries", as you can see from the errors. I don't understand why the compile process works and yet this fails.

My source tree layout looks like this...

git-repo-dir/
    .git/
    doc/
    lib/
        my_lib_a/
            common_lib_a.h
            common_lib_a.c
        my_lib_b/
            common_lib_b.h
            common_lib_b.c
    src/
        my_project/
            .cproj
            .project
            applilet3_config.cgp
            src/
            generate/

I added the library source code to my E2 Studio project by...

  • Right-clicking on the project name in E2's "Project Explorer" pane
  • Clicking Import and select File System
  • Browse to get-repo-dir and select (single-click) the lib folder
  • Check the box on the left pane to include all files in lib
  • Ensure "Create top-level folder" is selected
  • Click "Advanced"
  • Check the box for "Create links in workspace" and "Create virtual folders" and "Create link locations relative to:" is PROJECT_LOC
  • Finish

Then I add the include paths for the libraries to the build settings...

  • Right-clicking on the project name in E2's "Project Explorer" pane
  • Select "Properties"
  • Select C/C++ General > Paths and Symbols
  • Ensure configuration is the current/active one
  • Select the "GNU C" language
  • Click "Add" to add the following
    • "${ProjDirPath}/../../lib/my_lib_a"
    • "${ProjDirPath}/../../lib/my_lib_b"
  • Apply
  • Verify these paths are visible in C/C++ Build > Settings > Compiler > Includes

So in E2 Studio, the Project Explorer shows..

Archives/           (a virtual folder)
Includes/           (a virtual folder/list)
src/
generate/
lib/                (the virtual lib folder I added)
    my_lib_a/
    my_lib_b/

Any ideas why I'm getting a linker error?

1

There are 1 best solutions below

0
On BEST ANSWER

I eventually noticed that the build log didn't contain any C files from the lib/ folder.

The solution was simple. In E2 Studio, in the Project Explorer pane, I dragged the lib/ folder in to (on top of) the src/ folder.

Now the structure in Project Explorer looks like this:

Archives/           (a virtual folder)
Includes/           (a virtual folder/list)
src/
    lib/            (the virtual lib folder I added)
        my_lib_a/
        my_lib_b/
generate/

Evidently E2 Studio does not put source code that's outside of the src/ directory in the autogenerated make file. Or maybe there's some setting I missed. Nonetheless, since the C code wasn't compiled, there was no object file to link against, hence the linker error.