无法将流代码与 gcc 链接

发布于 2024-10-08 18:09:35 字数 1145 浏览 0 评论 0原文

我在编译以下代码时遇到问题:

// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("example.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}

编译:

g++ -c -O2 -Wall -Wno-unused -fexceptions  -I. -I../../../stub -D_REENTRANT -D_THREAD_SAFE  -I.  -o t.o ./test.cc

g++ -o t -O2 -Wall -Wno-unused -fexceptions -Wl,-brtl -Wl,-blibpath:/lib:/usr/lib t.o -lpthreads

编译给出一些警告:

ld: 0711-224 WARNING: Duplicate symbol: .__divdi3
ld: 0711-224 WARNING: Duplicate symbol: .__moddi3
ld: 0711-224 WARNING: Duplicate symbol: .__udivdi3
ld: 0711-224 WARNING: Duplicate symbol: .__umoddi3
ld: 0711-224 WARNING: Duplicate symbol: .__udivmoddi4
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

生成的二进制文件似乎执行正常:

$ ./t
$ echo $?
0

输出文件已创建但为空!?!

对于任何关于问题可能是什么的指示,我将非常感激。

I have a problem compiling the following code:

// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile ("example.txt");
  if (myfile.is_open())
  {
    myfile << "This is a line.\n";
    myfile << "This is another line.\n";
    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}

To compile:

g++ -c -O2 -Wall -Wno-unused -fexceptions  -I. -I../../../stub -D_REENTRANT -D_THREAD_SAFE  -I.  -o t.o ./test.cc

g++ -o t -O2 -Wall -Wno-unused -fexceptions -Wl,-brtl -Wl,-blibpath:/lib:/usr/lib t.o -lpthreads

The compile gives some warnings:

ld: 0711-224 WARNING: Duplicate symbol: .__divdi3
ld: 0711-224 WARNING: Duplicate symbol: .__moddi3
ld: 0711-224 WARNING: Duplicate symbol: .__udivdi3
ld: 0711-224 WARNING: Duplicate symbol: .__umoddi3
ld: 0711-224 WARNING: Duplicate symbol: .__udivmoddi4
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

The resulting binary appears to execute OK:

$ ./t
$ echo $?
0

The output file is created but empty !?!

I would be VERY grateful for any pointers as to what the problem might be.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大姐,你呐 2024-10-15 18:09:35

Libpath设置不正确,导致该问题。正确的设置应该是

LIBPATH=/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/

Libpath was set incorrectly, causing the problem. The correct setting should be

LIBPATH=/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文