Register    Login    Forum    Search    FAQ

Board index » Programming » C++




 Page 1 of 1 [ 6 posts ] 



Author Message
 Post subject: Linked Sources don't seem to Compile Correctly with Geany
 Post Posted: Thu Apr 19, 2012 3:25 pm 
Offline
Rookie
Rookie

Joined: Thu Apr 19, 2012 12:04 pm
Posts: 8
Languages: Python, Perl, Pascal, C, Java, BASIC, BASH, SQL
Text editor: Geany
Hello All..
My 1st Post in these Forums..
Working with Linux Debian 7 and g++ compiler 4.6

Problem...Building Linked Files Of Main, Class, Header with Geany
....Requires an #include Class.cpp at the beginning of the Main.cpp...
Should this BE?

I am working through the C++ tutorials now on #51..
However while I can and do use Eclipse and Or NetBeans for C++..
I prefer the Light weight Geany for tutorials but not for Projects..
I had been fine compiling all earlier Tutorials Main, Headers and Classes.
Once I reached the Constant Video #41 I began having Build Issues.
The issue was due to the Main not seeing the Class.cpp.. I keep each numbered tutorial video sources in a Separate Project Dir Each....
So, there should be no issues with the compiler seeing all sources for a given Project.

Any comments of Help Appreciated.
Source and Info from Geany and Eclipse Below


Geany 0.21
Compile: gcc -Wall -c "%f"
Build: gcc -Wall -o "%e" "%f"
Make: make %e.o

Eclipse Indigo 3.7
Compiler: g++ -O0 -g3 -Wall -c -fmessage-length=0

Geany
These are the 3 Mem Initializer Sources (this works with these Includes)
code:
#include <iostream>
#include "memclass.cpp"
#include "memclass.h"

using namespace std;

int main(int argc, char **argv)
{
   memclass memobj(3, 87);
   memobj.print();
   cout << "Hello Geany from C++!!" << endl;
   return 0;
}

#include "memclass.h"
#include <iostream>
using namespace std;


memclass::memclass(int a, int b)
: regVar(a), constVar(b)
{
   
   }
   
   void memclass::print() {
      cout << "regular var is: " << regVar << "  constant var is: " << constVar << endl;
}
.............

#ifndef MEMCLASS_H
#define MEMCLASS_H

class memclass
{
   public:
      memclass(int a, int b);
         void print();
   private:
      int regVar;
      const int constVar;
      
      /* add your private declarations */
};

#endif /* MEMCLASS_H */   

********************************

The MemInitializer w/ Eclipse (this Works)
Eclipse Code

code:
#include "memclass.h"
//#include "memclass.cpp"
#include <iostream>
using namespace std;

int main() {

   memclass memobj(3, 87);
      memobj.print();
      cout << "Hello Eclipse from C++!!" << endl;
      return 0;

   return 0;
}

 #include "memclass.h"
#include <iostream>

using namespace std;
memclass::memclass(int a, int b)
: regVar(a), constVar(b)
{

   }

   void memclass::print() {
      cout << "regular var is: " << regVar << "  constant var is: " << constVar << endl;
}

#ifndef MEMCLASS_H_
#define MEMCLASS_H_

using namespace std;

class memclass {

public:
      memclass(int a, int b);
         void print();
   private:
      int regVar;
      const int constVar;

      /* add your private declarations */


};

#endif /* MEMCLASS_H_ */


Top 
 Post subject: Re: Linked Sources don't seem to Compile Correctly with Gean
 Post Posted: Fri Apr 20, 2012 12:04 am 
Offline
Legendary User
Legendary User
User avatar

Joined: Thu Apr 28, 2011 5:20 pm
Posts: 2292
Languages: c++
Text editor: notepad++ :)
You can't include .cpp file like this: #include "memclass.cpp". You mus load this file as one of your projects source files to automatically link it to your project.

_________________
http://www.youtube.com/watch?v=eDn2Xp5ctQM :D


Top 
 Post subject: Re: Linked Sources don't seem to Compile Correctly with Gean
 Post Posted: Fri Apr 20, 2012 12:28 am 
Offline
Rookie
Rookie

Joined: Thu Apr 19, 2012 12:04 pm
Posts: 8
Languages: Python, Perl, Pascal, C, Java, BASIC, BASH, SQL
Text editor: Geany
Quote:
You can't include .cpp file like this: #include "memclass.cpp".


Thanks for the reply @krootushas...
but the above Does work as Geany unlike Netbeans and Eclipse does not create a make file which compiles the classes..
As it does work, do you mean to say You shouldn't include .cpp files like this

Bad Protocol.. or what?


Top 
 Post subject: Re: Linked Sources don't seem to Compile Correctly with Gean
 Post Posted: Fri Apr 20, 2012 9:15 am 
Offline
Legendary User
Legendary User
User avatar

Joined: Thu Apr 28, 2011 5:20 pm
Posts: 2292
Languages: c++
Text editor: notepad++ :)
Quote:
As it does work, do you mean to say You shouldn't include .cpp files like this

Yes.

So basically you should end up with two objects: memclass.o and main.o then link memclass.o to main.o and it should be compiled. If you include memclass.cpp in your main.cpp the compiler will not generate memclass.o.

_________________
http://www.youtube.com/watch?v=eDn2Xp5ctQM :D


Top 
 Post subject: Re: Linked Sources don't seem to Compile Correctly with Gean
 Post Posted: Fri Apr 20, 2012 9:23 am 
Offline
Mega-Power User
Mega-Power User
User avatar

Joined: Sun Jan 08, 2012 3:35 pm
Posts: 440
Location: Tonight
Languages: NASM x86_64, C, C++, D, Java, Python, Lua, HTML, CSS, PHP, JavaScript
Text editor: Geany
Geany does not have a build system. The build command only builds the currently active source file.

You will have to use an external build system (like Make) if you are to use geany with more than one source file.

Here is an excellent generic makefile for compiling C++ projects: http://sourceforge.net/projects/gcmakefile/

I, too use this as the makefile for my C++ projects.

_________________
C++ reference and C++ FAQ
My github page (Give me some love, send me pull requests!)
Remember to use a version control system (Git, Mercurial) for your projects! They make life a whole lot easier!


Top 
 Post subject: Re: Linked Sources don't seem to Compile Correctly with Gean
 Post Posted: Sat Apr 21, 2012 5:23 pm 
Offline
Rookie
Rookie

Joined: Thu Apr 19, 2012 12:04 pm
Posts: 8
Languages: Python, Perl, Pascal, C, Java, BASIC, BASH, SQL
Text editor: Geany
Hmmm.. Sorry people!!
I had attempted to reply to the above yesterday..I guess I didn't click the Submit..

Anyway... THanks Alot!
@krootushas you are spot on..
too many years of using an IDE which did the make for me left me ignorant as to what was happening with the Object files ..*.o

@GeekTard
I downloaded the generic Make template..Thank You..
Good to know that there is another Geany pilot on these forums.


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 6 posts ] 




Board index » Programming » C++


Who is online

Users browsing this forum: Bing [Bot] and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: