Using GCC to generate makefile dependencies.

  • Thread starter Thread starter TylerH
  • Start date Start date
  • Tags Tags
    Gcc
Click For Summary
To generate dependencies for makefiles using GCC, the -M option is commonly employed, but users often encounter issues with the syntax, particularly with the $< variable not being recognized correctly. This results in GCC failing to generate the necessary dependencies. A suggested solution involves using Autotools, which provides a robust framework for managing dependencies, although it may require significant setup depending on the complexity of the project. For simpler projects with fewer libraries, hard-coding dependencies might be a more practical approach. Additionally, the discussion highlights the importance of considering the operating system and specific libraries in use when determining the best method for dependency management.
TylerH
Messages
729
Reaction score
0
How do I use GCC to generate dependencies for makefiles? I tried using the -M option, like below, but I don't know how to insert the name of the .cpp into the shell command that calls GCC with the -M option.

Code:
%.cpp : $(shell gcc -M $<)

Instead of the desired effect, $< is replaced by nothing, causing GCC to generate an error and my attempt to generate dependencies to fail.
 
Technology news on Phys.org
I had the same problem that you do now. For that I did some googling around and found a set of tools called Autotools. Here is a pretty good explanation of what you might want to do:

http://www.freesoftwaremagazine.com/books/autotools_a_guide_to_autoconf_automake_libtool

This requires some effort to setup correctly (depends on the complexity of your compilation environment), so if you have only a small number of libraries, hard-coding would be a better option.

What operating system are you using? What libraries are you trying to use?
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
9K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K