Altera_Forum
Honored Contributor
12 years agoFunctions Inclusion
Hello every body; I have created macros to deal with my hardware component and put them in a separate .c file, how can I include these macros in my main.c file. Thanks.
That defeats the purpose of separating into .h and .c.
.h is used to keep declarations, macros, constants... but no actual code. .c is where definitions are stored. During compilation, every .c file is compiled individually, with all included files. The step generates an .obj file. Sections of codes (such as functions) in obj are identified using unique symbol names. After compilation, all .obj files are linked into an executable, replacing symbols into actual code addresses. In your case, if the included .c is also a source file (with function definitions) in the project, there will be multiple .obj files having same symbols. This will cause linker failure unable to resolve symbol address. However, linker can work if the included .c is a file without definitions, but you might as well name it .h to stick to usual convention. Maybe you want to paste relevant code sections here for us to have a clearer picture on what you like to achieve.