开发者

eclipse C++ add reference undefined reference to method error

I'm new to C++ and ecplice and they are definitely giving my a hard time :)

I'm tring to write simple application that includes main project with refernces to other project

i wrote the following file in shared project:

    
#ifndef MANAGEDLOG_H_
#define MANAGEDLOG_H_
#include string
#include iostream
#include fstream
    using namespace std;
 class ManagedLog 
{
 ofstream _fileStream;
public :
 ManagedLog::ManagedLog(string path);
 ManagedLog::~ManagedLog();
 void ManagedLog::WriteInfoLog(string message,string stackTrace);


};
#endif /* MANAGEDLOG_H_ */

/*
 * ManagedLog.cpp
 *
 *  Created on: 18/06/2010
 *      Author: Eran
 */
#include "ManagedLog.h"
#include iostream
#include fstream
ManagedLog::ManagedLog(string path)
{
 _path=path;
}
ManagedLog::~ManagedLog()
{
}
 void ManagedLog:: WriteInfoLog(st开发者_运维问答ring message,string stackTrace)
{
  ofstream myfile;
  myfile.open("Eample.txt",ios::app);
  myfile.close();


}

and run it in simple hellow world project:


    #include "ManagedLog.h"
#include 
using namespace std;

int main() {
 ManagedLog * log = new ManagedLog("path");
 log->WriteInfoLog("test","RunLog/Main");
 cout 

but I'm getting this error:

*** Build of configuration Debug for project RunLog ****

**** Internal Builder is used for build               ****
g++ -ID:\EclipseWorkSpace\LogManager -O0 -g3 -Wall -c -fmessage-length=0 -osrc\RunLog.o ..\src\RunLog.cpp
g++ -LD:\EclipseWorkSpace\LogManager\Release -oRunLog.exe src\RunLog.o
src\RunLog.o: In function `main':
D:/EclipseWorkSpace/RunLog/Debug/../src/RunLog.cpp:13: undefined reference to `ManagedLog::ManagedLog(std::string)'
D:/EclipseWorkSpace/RunLog/Debug/../src/RunLog.cpp:14: undefined reference to `ManagedLog::WriteInfoLog(std::string, std::string)'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 574  ms.  

I added #include "ManagedLog.cpp" and the code work just fine but i guess this is not the right way to do it i read a lot about it but found no answer that i can impliment since i don't understad the term is the reanswers can anybody please help me with the right way to point to other project or dll in this environment?

thanks

Eran


You're not building ManagedLog.cpp. Your compile sequence should look something like this example (simplified for clarity):

  1. compile RunLog.c into RunLog.o
  2. compile ManagedLog.c into ManagedLog.o
  3. link RunLog.o and ManagedLog.o into RunLog.exe

Steps 1 & 2 could be in the other order if you like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜