第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用G ++編譯多線程代碼

用G ++編譯多線程代碼

縹緲止盈 2019-11-30 13:25:00
我有史以來最簡單的代碼:#include <iostream>#include <thread>void worker(){    std::cout << "another thread";}int main(){    std::thread t(worker);    std::cout << "main thread" << std::endl;    t.join();    return 0;}盡管我仍然無法編譯g++運行它。更多細(xì)節(jié):$ g++ --versiong++ (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1Copyright (C) 2013 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.編譯命令:$ g++ main.cpp -o main.out -pthread -std=c++11正在運行:$ ./main.out terminate called after throwing an instance of 'std::system_error'  what():  Enable multithreading to use std::thread: Operation not permittedAborted (core dumped)現(xiàn)在我陷入困境。在互聯(lián)網(wǎng)上的每個相關(guān)線程中,建議在-pthread已經(jīng)擁有的情況下添加它。我究竟做錯了什么?PS:這是全新的ubuntu 13.10安裝。只有g(shù)++包安裝和次要之類的東西chromium等PPS:$ ldd ./a.out linux-vdso.so.1 => (0x00007fff29fc1000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb85397d000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb853767000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb85339e000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb85309a000) /lib64/ld-linux-x86-64.so.2 (0x00007fb853c96000)PPPS:使用clang++(v3.2)可以編譯并正常運行PPPPS:伙計們,這不是Linux下在GCC中使用std :: thread的正確鏈接選項是什么的重復(fù)項?PPPPPS:$ dpkg --get-selections | grep 'libc.*dev'libc-dev-bin                    installlibc6-dev:amd64                 installlibclang-common-dev             installlinux-libc-dev:amd64                install
查看完整描述

3 回答

?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗 獲得超2個贊

答案是由SO C ++聊天的一位好心人提供的。


看來此行為是由gcc中的錯誤引起的。


該錯誤討論的最后評論中提供的解決方法確實可以解決該問題:


-Wl,--no-as-needed


查看完整回答
反對 回復(fù) 2019-11-30
?
寶慕林4294392

TA貢獻(xiàn)2021條經(jīng)驗 獲得超8個贊

我有更高級的版本(4.8.4而不是4.8.1),并且我測試了以上所有三個答案。事實上:


-pthread 單獨工作:


g ++ -std = c ++ 11 -o main -pthread main.cpp


-Wl,--no-as-needed獨自一人行不通。


-lpthread獨自一人行不通。


-Wl,--no-as-needed并-lpthread 一起工作:


g ++ -std = c ++ 11 -o main -Wl,-無需按需main.cpp -lpthread


我的版本是“ g ++(Ubuntu 4.8.4-2ubuntu1?14.04.1)4.8.4”。


查看完整回答
反對 回復(fù) 2019-11-30
?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗 獲得超9個贊

已經(jīng)為qtcreator做出了答案:


LIBS += -pthread

QMAKE_CXXFLAGS += -pthread

QMAKE_CXXFLAGS += -std=c++11

對于控制臺g ++:在這里


g++ -c main.cpp -pthread -std=c++11         // generate target object file

g++ main.o -o main.out -pthread -std=c++11  // link to target binary


查看完整回答
反對 回復(fù) 2019-11-30
  • 3 回答
  • 0 關(guān)注
  • 765 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號