Source code in Projects

Asked

Viewed 225 times

4

If I have 10 projects in Netbeans, these 10 projects will use a log recording system, this system contains a log. h and a Log.c. Since all projects will have to use these two log files to generate logs, I will need to copy the two files for each project. But this causes a problem, for example: if I will change the Log. c I will have to change in all projects. In this case, there is some way to include these two files in all projects without having to copy the two files for each project?

  • 3

    One idea is to make a library/library with Log. c and include Log. h in the files that use the Log.c. functions. I don’t put this as an answer below because I’m not sure how to do this in Netbeans. You should also be able to add the same Log. c to 10 projects, and get a single Log. c file for all.

  • Why are the tags [tag:c#] and [tag:java] part of this question?

  • 1

    An error, I’ve corrected.

2 answers

5


I cannot comment and as I do not know which compiler you are using I will put here a general answer.

You will need to create a static library. Let’s assume it’s called liblog.a in your compiler you will need to add the flag -llog, that is to say, -l replaces lib( must always have lib in the name! ).

In addition, you must have a header file containing the prototypes of your functions in order to invoke them in your program, in this case Log. h.

To make your life easier you can put the static library in the default LIBRARY_PATH of your compiler and its header file Log.h in the default INCLUDE_PATH of your compiler, they are usually respectively liband include the name of those directories.

Or if you want you can create your own directories to place your libraries and headers, but you will always have to indicate your location to the compiler.

  • This liblog. a, must have only the implementation of the prototypes defined in Log. h?

  • It may have more, but it may also have other functions that are used by the defined prototypes, or even variables.

  • I get it, what I wanted to know now is whether the use of static libraries is convenient for developing systems?

  • What kind of systems? Operating?

  • Commercial systems such as ERP etc

  • I think so, I’m not sure :/

Show 1 more comment

1

Create a folder with the files you want to share among the various projects. Then open the desired project and right-click on the project and select Adicionar Item Existente da Pastas... add the desired folders and click add. The folders will be indexed to the project.

To include in other projects just repeat the steps in the projects you want. Surgeri do this with folders because it is easier for the organization, the same can be done by files, the only difference is that you will have to select the option Adicionar Item Existente....

After adding the files or folder in the desired projects just change the files in common since all projects will have access to change. I only used this netbeans feature in Java and C but I think there is support for all programming languages.

  • It’s a good way, but it also depends, some projects may only need a few files from that folder, and you end up including unnecessary things to the project.

  • @Vynstus read the second paragraph again, your point is raised there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.