【问题标题】:C++ code compiles on mac but not on linux [duplicate]C ++代码在mac上编译但不在linux上[重复]
【发布时间】:2016-01-06 18:59:24
【问题描述】:

我的代码在我的 mac 上运行良好,但在 linux 上无法编译。我得到编译错误

/tmp/ccWcFSEW.o: In function `main':
DroneMap.cpp:(.text.startup+0x22d): undefined reference to `pthread_create'
DroneMap.cpp:(.text.startup+0x262): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status

有谁知道这个错误信息是什么意思,或者我为什么会得到它,因为我无法弄清楚。

CXX=g++
CXXFLAGS=-Wall -O3

all: DroneMap

clean:
    rm -rf DroneMap

【问题讨论】:

  • 这些是链接器错误。它无法解析对 pthread 库的调用。检查以确保链接器可以找到 pthread 库(通常通过 -L 选项)。
  • 试试this answer
  • 您的代码想要链接pthreads 库。确保在编译和链接时指定了-pthread

标签: c++ linux


【解决方案1】:

你需要在你的编译命令中包含pthread库,我不知道你是如何在MAC中编译的,但是linux下正确的编译命令应该是这样的。

CXX=g++
CXXFLAGS=-pthread -Wall -O3

all: DroneMap

clean:
    rm -rf DroneMap

【讨论】:

  • 对不起,我对制作文件了解不多,我将如何更改我的 CXX=g++ CXXFLAGS=-Wall -O3 all: DroneMap clean: rm -rf DroneMap
  • 在您的文章中添加您的 make 文件,以便我们为您提供帮助
  • 在我的回答中看我的修改
猜你喜欢
  • 2013-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多