Solved

Linux C++ Makefile

Posted on 2014-09-10
7
209 Views
Last Modified: 2015-01-05
I have two issues
1) all my files are in the same directory but when i compile  (G++) it does not find my .h file. Only if I include the fulll path for the .h file in the include statement does it work. Why is the compile not finding it in the same directory?

2) When I run the following make file I do not get and exe file?

all: Magic.x
Magic.x: test.o test.o
        g++ -o test.x test.o test.o
test.o: test.cpp
        g++ -c test.cpp
Magic.o: Magic.cpp
        g++ -c Magic.cpp
clean:
        rm -rf *.o *~ *.x
0
Comment
Question by:pcomb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40314202
How did you include your .h file?  with <> or ""?
How are your include paths defined?

Did you get any errors running make?
g++ -o test.x test.o test.o
would either define main 0 times or 2 times,
executables should declare it declared exactly once
0
 

Author Comment

by:pcomb
ID: 40314211
my include file is
#include </home/abc/xyz/proj/test.h>

Not sure I follow the questino on include path?

No errors

0 or 2 times not sure what you mean for this?
0
 
LVL 84

Expert Comment

by:ozo
ID: 40314221
test.o is linked twice,
if test.o contains main(), it will be a duplicate symbol, and the link will fail
if test.o does not contain  main(), it will be an undefined symbol, and the link will fail
when you ran make, it should have given you an error message to tell you which way it failed.
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40314236
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header identified uniquely by
the specified sequence between the < and > delimiters,
these are usually system include directories.

# include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified
by the specified sequence between the " delimiters. The named source file is searched
for in an implementation-defined manner.
these searches are usually relative to the current directory
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40320523
>>    g++ -c Magic.cpp
The above creates Magic.o, but there is no line that uses Magic.o.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 40320526
>>  all: Magic.x
>>  Magic.x: test.o test.o
>>           g++ -o test.x test.o test.o         // this is trying to create an executable called, test.x

Without seeing an outline of your code, I can only take a guess. Assuming that you want only one executable, Magic.x, and not an executable, test.x, and assuming that there is one main() function in either test.o or Magic.o, then try this:

all: Magic.x
Magic.x: Magic.o test.o          // Magic.x executable is dependent on Magic.o and test.o
         g++ -o Magic.x  Magic.o  test.o      // build Magic.x from Magic.o and test.o
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Introduction to Processes

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question