help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trouble linking through g++


From: John Calcote
Subject: Re: Trouble linking through g++
Date: Thu, 15 Oct 2009 10:44:09 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.4pre) Gecko/20090915 Thunderbird/3.0b4

Hi Madhav,

On 10/15/2009 8:03 AM, Madhav Ancha wrote:
Hi,

   When I run the linker through the command line like this, it works. 
      g++ -g -pg -fprofile-arcs -ftest-coverage -Lrelease1 -o testApp file.o -lSharedLib
   
   But when i run from a make file with the follow equivalent commands, it does not. It gives the error reproduced below. can you help debug the cause. 

     LINK_FLAGS= -g -pg -fprofile-arcs -ftest-coverage -fPIC -Lrelease1
      testApp: file.o -lSharedLib
      $(CXX) $(LINK_FLAGS) -o $@ $^

Error:
     make: *** No rule to make target `-lSharedLib', needed by `testApp'.  Stop.

A makefile contains rules and command (and other things). Rules are lists of targets, followed by separator (colon, double-colon, etc), followed by lists of dependencies. Commands are lines prefixed with a TAB character. In your rule, you have a linker option (-lSharedLib) in your dependency list. The target list and the dependency list must only contain file names, or macros that resolve to file names, or patterns (containing '%' or '*' characters) that can match file names. You can't put anything else into either the target or dependency list. What you probably wanted to write was this (untested):

LINK_FLAGS= -g -pg -fprofile-arcs -ftest-coverage -fPIC -Lrelease1
testApp: file.o
$(CXX) $(LINK_FLAGS) -o $@ file.o -lSharedLib

Note that I changed $^ to file.o in the command line because $^ is not portable between various flavors of make.

John

reply via email to

[Prev in Thread] Current Thread [Next in Thread]