LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-01-2011, 06:39 PM   #1
OnlySolitaire
LQ Newbie
 
Registered: Feb 2011
Posts: 6

Rep: Reputation: 0
Using makefile - 'Multiple Definition' compile errors


As part of an assignment, our class was given a small set of c++ classes which are compiled using a makefile.

As part of the assignment, I have created a namespace and saved in it a .cpp file. The functions, constants and typedefs from the namespace are now used in one of the original files, and so I added an <#include MyFile.cpp> to the file I modified, in addition to a using MyNamespace;


When I try to use the original makefile, the compiler gives a lot of errors about multiple definitions of every function in the namespace.

What do I need to do to resolve this? Do I need to change the makefile or one of the files themselves? I am new to Linux programming and makesfiles.


I can post the actual files if needed.
 
Old 03-01-2011, 11:56 PM   #2
Awatto
Member
 
Registered: Aug 2003
Location: Halifax, NS
Distribution: Debian, Gentoo, Ubuntu, Fedora
Posts: 128

Rep: Reputation: 30
Hi OnlySolitaire,

The Programming forum would have likely been a better choice. (Many Linux users know very little or even no programming, and this isn't really a Linux-newbie question)

In any case, it is hard to tell exactly what is going on without seeing the source for your makefile, cpp files, hpp files, and the errors. Perhaps use pastebin or something similar for that.
 
Old 03-02-2011, 12:33 AM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Quote:
Originally Posted by OnlySolitaire
and so I added an <#include MyFile.cpp> to the file I modified
Maybe you were using a shorthand, but just in case...

If you created a header file to be included by other cpp files, then 99% of the time, it should be included like this:
Code:
#include "MyFile.hpp"
So-called system header files use something like "#include <vector>" -- these header files are stored in pre-determined directories on the computer you're working with. Your header file is extremely unlikely to be in one of those directories.

Also, by convention, headers have a "hpp" extension and contain only #defines, class definitions, and other data type definitions--no executable code (i.e. functions) at all.

Again, by convention, a header file should have something like this:
Code:
#ifndef MYFILE_HPP
#define MYFILE_HPP

/* Place the content of your header file here */

#endif
This prevents re-definition errors when you have multiple cpp files #include'ing the same hpp file.
 
  


Reply

Tags
c++



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multifile Rule definition in Makefile sahil.jammu Linux - Newbie 1 08-29-2010 07:45 AM
compile multiple modules in Makefile sharathkv25 Programming 1 04-11-2007 03:28 PM
configure Makefile to compile for multiple platforms StargateSteve Programming 0 03-26-2007 11:54 AM
duplicated definition for a target in Makefile George2 Programming 2 05-07-2006 04:01 AM
multiple definition ? lackluster Linux - Software 1 11-27-2003 05:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration