Using GCC to generate makefile dependencies.

  • Thread starter Thread starter TylerH
  • Start date Start date
  • Tags Tags
    Gcc
Click For Summary
SUMMARY

Using GCC to generate makefile dependencies can be achieved with the -M option, but requires proper syntax to avoid errors. The command structure should include the specific .cpp file name, which can be inserted using a makefile variable. For complex environments, utilizing Autotools is recommended, although it requires significant setup effort. For simpler projects, hard-coding dependencies may be more efficient.

PREREQUISITES
  • Familiarity with GCC command-line options
  • Basic understanding of makefile syntax
  • Knowledge of Autotools for dependency management
  • Experience with C++ compilation processes
NEXT STEPS
  • Research the use of GCC -M option for dependency generation
  • Learn about makefile variable usage and syntax
  • Explore Autotools setup and configuration
  • Investigate hard-coding dependencies in makefiles for small projects
USEFUL FOR

C++ developers, build system engineers, and anyone involved in managing makefile dependencies using GCC.

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?
 

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
3K
  • · Replies 9 ·
Replies
9
Views
9K
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K