【问题标题】:Compilation of mutiple files in c++ solaris在 c++ solaris 中编译多个文件
【发布时间】:2012-12-10 13:43:45
【问题描述】:

我有三个简单的文件:

类的头文件

> cat myhh.hh
#include<iostream>

class helloworld
{
string str;
public:
void start(string &);
void stop(string &);
};

对应的cc文件

> cat myhh.cc
#include<iostream>
#include "myhh.hh"
using namespace std;

void helloworld::start(string &str1)
{
  cout<< ""function started"<<endl;
}
void helloworld::stop(string &str2)
{
cout<< ""function stopped"<<endl;
}

现在主要功能:

> cat mymain.cc 
#include<iostream>

#include "myhh.hh" 

int main()
{

helloworld obj;
obj.start(std::string("XXXX"));
obj.stop(std::string("XXXX"));


}
>

我的主要意图是用这 3 个文件生成 a.out,当我执行它时它应该打印出来:

function started
function stopped

我尝试编译,但出现以下错误。

> CC mymain.cc
Undefined                       first referenced
 symbol                             in file
void helloworld::stop(std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) mymain.o
void helloworld::start(std::basic_string<char,std::char_traits<char>,std::allocator<char> >&) mymain.o
ld: fatal: Symbol referencing errors. No output written to a.out
> 

我确定我没有掌握正确的基础知识。但这只是我试图学习编译过程的东西。 有人可以帮忙吗?

【问题讨论】:

    标签: c++ compiler-construction compilation solaris


    【解决方案1】:

    您还需要编译 myhh.cc 并链接生成的对象

    $CC -c myhh.cc -o myhh.o
    $CC -o mymain mymain.cc myhh.o
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-02
      • 2018-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      相关资源
      最近更新 更多