I have a problem including an external header with the related .c-file ( both in a folder outside the project-folder) to an existing project.
I have several projects for Atmel AVR microcontrollers. Some of them are packaged into one Git-Repo as a logical unit (hardware-level). Common headers and related Source-Files (e.g. twi, usart) are located in separate Git-Repos which are included as submodules.
Just to show quick what I am talking about, the project is set up like this (-
= folder, *
= file):
Git-repo_1
-project_1 (avr-gcc)
- config (header-files to be included in header-files in the common-folder; project-specific)
* avr_twimaster_cfg.h
* avr_twislave_cfg.h
- share (header-files with project-specific definitions to be included in "project_[2:5]")
* project_1_interface.h
- Debug (Build-Config Folder with makefile)
* makefile
- Release (Build-Config Folder with makefile)
* makefile
* main.h (main project header, includes <avr_twimaster/avr_twimaster.h>, <avr_twimaster/avr_twimaster.h>)
* main.c (main project source, includes "main.h")
* functions.c (functions to be used in main.c, includes "main.h")
* opt. more files
- project_2 (avr-gcc)
- project_3 (avr-gcc)
- project_4 (avr-gcc)
- project_5 (avr-gcc)
- common (no toolchain)
- avr_twimaster (Git-Submodule)
* avr_twimaster.h (includes <avr_twimaster_cfg.h> from any project)
* avr_twimaster.c (includes "avr_twimaster.h")
- avr_twislave (Git-Submodule)
* avr_twislave.h (includes <avr_twislave_cfg.h> from any project)
* avr_twislave.c (includes "avr_twislave.h")
In "Project-Properties/C,C++ Build/Settings/Tool Settings/AVR Compiler/Directories" I added:
"../../common"
"../share"
"../config"
These paths are added to the makefile with -I e.g. "-I../config".
NOTE: It is important that all paths are relative to the projectfolder and are included in the makefile so the project can be compiled without eclipse or with another computer with different paths.
My Problem: Even eclipse seems to know where to look for the included header-files: When I ctrl-click on a function in "functions.c", I jump to the correct header "avr_twislave.h" in the "common"-path. But a ctrl-click on the function in the header does not jump to "avr_twislave.c" and vice verca. Functions are same in name and parameters. "avr_twislave.h" is included in "avr_twislave.c".
When I try to compile the project I get many errors "undefined reference to..." which is obvious since the connection between Header and Source is broken. Looking at the console, the errors happen in the linker section - but I don't know if the linker itself is the problem or it just cant link something that wasn't compiled by the compiler. In the compiler-output I don't see any section with the external header-files/source-files in the common-folder. Only source-files directly in the project-folder are compiled.
I spent several hours with this problem and read through many posts but have not found a solution that worked.
What I want:
- Tell avr-gcc (through eclipse) to use the header/source in the external folder.
- Folder setup is more or less critial, since the external headerfiles/sourcefiles should be used by all projects and within the Git-Repo as submodules. Putting the "libs" into the project-folders is not an option.
- Info about the "libs"/folders must be in the makefile or another file included by the makefile and not just inside eclipse
- Paths must be relative to project-folder/makefile-folder
What I already tried:
- Paths in "Tool Settings / AVR Compiler / Directories" work for the Index (at least the header).
- Paths in "AVR Assembler"
- Paths in "AVR C Linker"
- countless variations how to include the external headers from within the project-files
- Paths under "Paths and Symbols" seem to be the same as in the Toolchain-Options and were added automatically.
- Linked Resources seem to be absolute in path
- Environment Variables also seem to be absolute
Please let me know if my question needs some clarification or additional info.