Solved

Linux C++ Makefile

Posted on 2014-09-10
7
208 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
youtube blocking politics 4 100
convert Systemjs to Webpack 3 122
WordPress: Debugging from my Windows 10 Desktop 6 91
grep command usage 10 24
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn different types of Android Layout and some basics of an Android App.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

739 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