【问题标题】:Compiling c++ program with multiple files用多个文件编译 c++ 程序
【发布时间】:2013-07-03 06:06:38
【问题描述】:

我正在尝试编译一个包含多个文件的 c++ 程序!

mainfile.cc

#include<iostream>
#include "funcfile.hh"
int main()
{
init();
}

函数文件.hh

#include<iostream>
void init();

funcfile.cc

#include<iostream>
#include "funcfile.hh"
using namespace std;

void init()
{
cout<<"hi"<<endl;
}

我正在创建如下二进制文件:

> CC funcfile.cc mainfile.cc -o output
funcfile.cc:
mainfile.cc:
ld: warning: symbol .dynsym[19] has invalid section index; ignored:
        (file /usr/local/opt/SunWorkShop/sws_5.0/SUNWspro/lib/libm.so value=19);

当我执行输出时:

> ./output
hi
>

但我在这里关心的是我是否应该在编译期间关心消息:

ld: warning: symbol .dynsym[19] has invalid section index; ignored:
            (file /usr/local/opt/SunWorkShop/sws_5.0/SUNWspro/lib/libm.so value=19);

CC 版本是:

> CC -V
CC: WorkShop Compilers 5.0 98/12/15 C++ 5.0

【问题讨论】:

  • 您可以看到我正在使用的编译器版本及其 c++ 编译器。我正在删除标签 C
  • 但是您的问题是关于编译 C 程序。好的,我修好了。
  • 您应该在funcfile.hh 中添加包含防护。
  • 尝试使用g++编译器!
  • 它说是数学库的错...

标签: c++ compiler-construction compilation compiler-errors


【解决方案1】:

您使用的编译器已经使用了将近 15 年。在那段时间里,ELF 格式发生了一些变化,您的编译器似乎无法识别一些较新的特殊节索引(参见例如here, table 7-4)。无需担心此警告,但如果可能,我建议使用更新的编译器。

【讨论】:

    猜你喜欢
    • 2012-02-02
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多