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
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...
Import
and select File System
get-repo-dir
and select (single-click) the lib
folderlib
PROJECT_LOC
Then I add the include paths for the libraries to the build settings...
C/C++ General > Paths and Symbols
"${ProjDirPath}/../../lib/my_lib_a"
"${ProjDirPath}/../../lib/my_lib_b"
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/
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.