작은 스레딩 예제 (Linux)를 제대로 컴파일하기 위해 scons를 얻을 수 없습니다. 다음C++ 스콘으로 std :: thread 예제 컴파일
[email protected]:~/projects/c++_threads$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o build/main.o -c -std=c++11 -pthread -Wall -g src/main.cpp
g++ -o build/c++threads build/main.o
scons: done building targets.
내가 ./build/c++threads
을 실행할 경우이 오류가 발생합니다 :
내가 SCons는 실행하면,이 수행
내가이 함께 명령 줄에서 컴파일하는 경우terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted
:
g++ -std=c++11 -pthread -Wall -g src/main.cpp
는 a.out
로 컴파일, 내가 실행하는 경우 a.out
그것을 RU ns 프로그램 (스레드에 대한 출력 등).
여기 내 SConstruct 파일입니다 :
# Tell SCons to create our build files in the 'build' directory
VariantDir('build', 'src', duplicate=0)
# Set our source files
source_files = Glob('build/*.cpp', 'build/*.h')
# Set our required libraries
libraries = []
library_paths = ''
env = Environment()
# Set our g++ compiler flags
env.Append(CPPFLAGS=['-std=c++11', '-pthread', '-Wall', '-g'])
# Tell SCons the program to build
env.Program('build/c++threads', source_files, LIBS = libraries, LIBPATH = library_paths)
여기에 CPP 파일입니다 :
#include <iostream>
#include <thread>
#include <vector>
//This function will be called from a thread
void func(int tid) {
std::cout << "Launched by thread " << tid << std::endl;
}
int main() {
std::vector<std::thread> th;
int nr_threads = 10;
//Launch a group of threads
for (int i = 0; i < nr_threads; ++i) {
th.push_back(std::thread(func,i));
}
//Join the threads with the main thread
for(auto &t : th){
t.join();
}
return 0;
}
누구든지 내가 잘못 어떤 생각을 ???
감사합니다.
건배 의견에 대한
@Joachim에자렛
링커 플래그에도'-pthread'를 추가하지 않아도됩니까? –
@JoachimPileborg 링크 및 컴파일이 두 단계로 수행되면 예. – inf