Home  >  Support  >  Support Forum  >  How do I place a library in global scope so all c files can see it?
Notice! We've recently migrated to using a new forum, we hope you enjoy it. If you are an existing member and this is your first time visiting our new forum, please reset your password to be able to sign in.
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How do I place a library in global scope so all c files can see it?

0 votes
How do I get a library into the global scope so all C files will be able to use it?
If it is possible, specifically how do I accomplish this?
asked Dec 5, 2013 in Rabbit Software by RickMcDonald New to the Community (3 points)
I'm using 10.72 with the c files added to the project window btw.

Please log in or register to answer this question.

2 Answers

0 votes
I assume you are using Project Explorer and multiple c files. I think you can #include the file in a header file and #include the header file in whichever c file needs it.

The basic rules for structuring Project Explorer projects are as follows:

1) Eliminate .H files from the Project Explorer window. Instead, #include .H files as needed in the various .C files.

2) Functions, macros and typedefs (including structure typedefs) which are accessed in multiple .C files should be prototyped / defined / typedef'd in a .H file and the .H file #included by each file that accesses the function / macro / typedef. Generally, the prototype / macro / typedef would be placed in the .H file corresponding to the .C file where the function / macro / typedef is implemented / associated / instantiated.

3) Declare global variables to be extern in the appropriate .H file. If the global variable is a structure, declare the extern structure variable following the structure definition / typedef. For example, keep "bbram cfgstruct Cfg;" in main.C but put "extern bbram cfgstruct Cfg;" in main.H, following the cfgstruct typedef.

I also suggest reading any ANSI C book which discusses file scoping.
answered Dec 11, 2013 by trooper2 Veteran of the Digi Community (346 points)
0 votes
Thank you very much for the answer. I realize now from your answer that I needed to be a little more specific. I think the answer to my question is to #use the DC libraries in each source file that needs them. I tried this and it seems to work except for a few caveats, that I finally worked out. I'm a programmer coming from an ANSI C background trying to figure out DCs way of doing things.
answered Dec 11, 2013 by RickMcDonald New to the Community (3 points)
Contact a Digi expert and get started today! CONTACT US