Welcome to PhoneASK, where you can ask questions and receive answers from other members of the community.

Configure eclipse with c++11

asked 8 days ago by notmii

First of all, I have already checked different solutions:

Threads std::system_error

Threads std::system_error II

Compile multithreading with gcc

Bug gcc multithreading

My environment:

Ubuntu 1404 64bits

gcc 4.8.2

Eclipse IDE for C/C++ Developers

Version: Luna Service Release 1 (4.4.1) Build id: 20140925-1800

Following these links I managed to compile and run a basic thread program(the code was taken from one of the links in SO, but cannot find it again. If someone sees it, please edit my question to add the reference).

#include <iostream>
#include <thread>
#include <vector>

void func(int tid)
{
    std::cout << "Launched by thread " << tid << std::endl;
}

int main()
{
    std::vector<std::thread> th;

    int nr_threads = 10;
    for(int i = 0; i < nr_threads; ++i)
    {
        th.push_back(std::thread(func, i));
    }

    for(auto &t : th)
    {
        t.join();
    }

    return 0;
}

The command I use to compile it is the following(THIS WORKS and the output file is executable):

g++ --std=c++11 -pthread test.cpp -o test.out

Launched by thread 1
Launched by thread 5
Launched by thread 3
Launched by thread 6
Launched by thread 4
Launched by thread 0
Launched by thread 7
Launched by thread 8
Launched by thread 9
Launched by thread 2

The problem is when I try to setup my eclipse project. I can compile but it cannot produce a valid runnable output.

Compile log:

12:09:45 **** Incremental Build of configuration Debug for project test ****
make all 
Building file: ../test.cpp
Invoking: GCC C++ Compiler
g++ --std=c++11 -pthread -D__cplusplus=201103L -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test.d" -MT"test.d" -o "test.o" "../test.cpp"
Finished building: ../test.cpp

Building target: test
Invoking: GCC C++ Linker
g++  -o "test"  ./test.o   
Finished building target: test


12:09:46 Build Finished (took 780ms)

I was changing different settings for the builder, dialects... as they say in the links trying to get the same command I can use to compile from the terminal. But no way to create a valid output file from the eclipse. It always shows this error:

terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted

Any idea how to setup eclipse?

Update: Following the indications of @Dirk I tested in a virtual machine and it works just adding the pthread to the linker libraries.

But for my initial setup it still fails. I made it working after modifying the C/C++ Build settings G++ linker command to g++ --std=c++0x -pthread

So, it seems obvious that my first environment is missing something.

Your answer

1 Answers

answered 8 days ago by Steve Buzonas

Seems like linking with the pthread library is missing. Add "pthread" under Build->Settings->Tool Settings->GCC C++ Linker->Libraries.

This is what my build log says:

**** Build of configuration Debug for project testpthreads ****

make all 
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 --std=c++0x -pthread -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: testpthreads
Invoking: GCC C++ Linker
g++  -o "testpthreads"  ./main.o   -lpthread
Finished building target: testpthreads

Your code then works and outputs:

Launched by thread Launched by thread Launched by thread 1
Launched by thread 0
Launched by thread 2
Launched by thread 9
Launched by thread 3
Launched by thread 7
Launched by thread 6
4
Launched by thread 8
5

I get the same error as you Without -lpthread

My linker settings: linkersettings

Related Questions

I downloaded the plugin from http://www.normalesup.org/~simonet/soft/ow/eclipse-less.en.html. and installed in on eclipse however when I try to compile the less to css I get this error Cannot be launc
I am writing some string conversion functions similar to atoi() or strtoll(). I wanted to include a version of my function that would accept a char16_t* or char32_t* instead of just a char* or wchar_t
This is a general question but my current problem revolves around menu handling. In a normal plugin with contributes menu actions you would configure ActionSets etc in the plugin.xml configuration. T
I have a drl file that needs proper formatting including indentation. Is there a plugin for that?
I have a maven-multi project, when I create a new eclipse project from it (by M2E 1.0 Checkout Maven Project from SCM) I want that the eclipse checkstyle plugin is configured for that project automat
I am trying to decipher a note that led to a change between C99 and C11. The change proposed in that note ended up in C11's 6.2.4:8, namely: A non-lvalue expression with structure or union type, wher
I've a doubt about a sentence in this paragraph of the standard C11: 5.1.1.1 Program structure A C program need not all be translated at the same time. The text of the program is kept in units called
Using the _Generic feature in C11, how do you deal with string literals? For instance: #include <stdio.h> #define foo(x) _Generic((x), char *: puts(x)) int main() { foo(Hello, world!); return
All our projects are built using maven. we have centralized some of our main configuration within a super pom. In order to always have an update version of this super pom (without having to modify the
I have an eclipse project where every source folder has its own associated output folder. Instead of /classes it's called /eclipse-classes. So if I have a folder: src/main/java (typical maven thing)
This might be a GDB question.. but I'd like to run my app in the debugger and have the debugger break when an exception is thrown, so I can see where the code is and what its doing at that time. I do
What is the correct parameters to get Beyond Compare 3 working with Eclipse/Subclipse conflict resolution? In Preferences > Team > SVN > Diff/Merge there's the option to specify an external p
I have maybe dump question but it can't get it off my mind. I'm starting to learn SWT and wonder why it's recommended to use SWT like imported project in Eclipse as described in eclipse wiki. Isn't it
I begun this Spring MVC Step-By-Step Tutorial part 1 at 1.8 it says If you are using an IDE, you will want to configure your project's build path by adding the jars from the 'lib' directory. You wil
Eclipse 3.7.1 CDT 1.4.1 GCC 4.6.2 This is an example of a piece of C++11 code: auto text = std::unique_ptr<char[]>(new char[len]); The Eclipse editor complains about: Function 'unique_ptr' coul
I am developing web applications using eclipse with php etc. How can I tell eclipse to suggest stuff (autocomplete) while I do something like: <li class= <-- here suggest available classes <
I've found this, but didn't work in my case. I'm using eclipse indigo SR1 in a linux Fedora 32 bits. It's virtualized by VMWare Player. All applications in this linux is working when I configure the p
I am working with Eclipse 3.7, on an Windows XP environment behind a web proxy. I want to install the Groovy plugin on a newly unzipped Eclipse Indigo (Eclipse Java EE Indigo M4). I added the update s
I have a problem with Mac and the terminal. I need to compile a program. Xcode and command line tools are installed. After cmake one needs to press c to configure and then g to generate the makefile.
I just suffer a problem that the all the things works well on my ubuntu. However, I want to get things work on my mac, bad thing happens. it shows the following errors cc1plus: error: unrecognized com
I have installed and configured NetBeans 6.7 for c++ according to the official manual: http://www.netbeans.org/community/releases/67/cpp-setup-instructions.html#mingw Configuration window looks like t
I'm working on a C++ project on GNU/Linux and I'm looking for a way to test the existence and usability of IBM Informix's library with the Autotools - namely, editing a configure.in. I don't have expe
I'm stumbled upon a problem while developing a Web Application based on Struts2 with Spring and Hibernate. When I refresh the site a few times, for example 2-4 times, Hibernate is showing up an except
I downloaded the c++ plugin for intelliJ from http://plugins.intellij.net/plugin/?id=1373 and the sdk from: http://www.microsoft.com/downloads/details.aspx?FamilyId=E6E1C3DF-A74F-4207-8586-711EBE331CD
I have downloaded the CPP Unit Test framework and trying to compile for the Android. But, facing the Configure issues. I tried making Standalone tool chain and also tried configuring but its always fa
I am trying to run Fix8 at Fix8.org. I am following the README instructions as explained at: https://github.com/dakka/fix8 I am getting an error when running the ./configure command? It results in: c
The output we get when printing C++ sources from Eclipse is rather ugly. Is there are way/a plugin to pretty print C++ source code like e.g. with a2ps (which is probably using yet another filter for
I am trying to run eclipse on a remote 64 bit ubuntu 11.04 using x11 forwarding.I have ubuntu at my client side. My /etc/ssh/ssh_config contains at the server contains: Host * ForwardX11 yes SendEnv
Does anybody know how to add a C/C++ project nature to an Eclipse project through the UI ? I'm importing a project and working with legacy code that was originally started in Visual Studio 4 and I'd r
I am using Eclipse IDE on ubuntu to code in C. I use its normal debugging and default compiler ( GCC ) am writing code with OpenMP features. Eclipse just skips the pragmas and compiles the code in se
As far as I know it is hard to learn using Eclipse from scratch. But I will get such benefits as fast source code browsing, call graphs, static code analysis. What other benefits will I get from using
I need to add a C library to C project in Eclipse indigo. What I've done so far. I've downloaded and installed the library. All headers are in folder /usr/include, library.so files are in folder /usr/
I've been googling for about 2 days. Read and followed a lot of instructions but nothing worked for me (including some instructions in this website; I know that people already asked this question in h
I was trying to set up my development environment on Eclipse CDT for C++ and although the auto-complete is working (it finds classes like vector and such) it shows no documentation on C++ stuff, only
I am trying to install CDT in eclipse to set the c++ development environment.I want to install MinGW in eclipse.I have tried many ways but not succeed . I have used following link : https://www3.ntu.e
Need to deploy the web samples from IIS Express 7.5 server. I have some web samples in different platforms (Asp.NET,Asp.Net MVC, Silverlight) projects. i have created a startup exe to run the sample b
In Admob I have 2 ways to configure iAd mediation with Admob eCPM - (I set eCPM per ad network) % - I set % shares (+ country targeting as optional choice) I wish to show iAd when available and admo
i'm realizing an admin panel and i need to toggle an option on/off. Everything works fine, except for the Configure::write() method that looks like if it's not permanent. Here is the ajax handler. ca
Looking at RivetsJS pull request 186 one sees that you can now build custom tags (component/ reusable views). But I haven't seen any documentation that shows a full example and how it works. I tried
I am using this command to crawl some URLs: ./bin/nutch crawl urls/urls -dir crawl -depth 2 It is showing the following error: Could not find or load main class org.apache.nutch.crawl.Crawl How can
It may seem to be asked several times, but I could not find answers to my doubts. As one needs to setup an MDM server, what are the things that need to be available or installed on this server. Is th
I'm creating a self-hosted REST service using service stack & AppHostHttpListenerBase. I'd like to use a base URI for my services (e.g. api) like so: http://myserver/api/service1/param http://my
Currently i am working on cakephp with nginx. I setup a cakephp environment on a Centos server running Nginx with Fact CGI. The problem is that I cannot get the rewrite rules to setup correct in my vh
I am trying to add a library to C/C++ project in Eclipse by the following procedure: Properties->C/C++General->includes (within includes specifying the folder in which the library is kept). Pro
I'm compiling a C program for an embedded application using eclipse, but I need the code to know (at runtime) where exactly it ends in flash. What is the simplest way of doing this? Thanks
Have anyone successfully managed to setup a combined Java/C++ project for Eclipse? What I am trying to do is quite simple; 1) Compile my Java sources 2) Run Javah to create the JNI interface 3) Compil
I found a very tempting function in Netbeans, which is to re-factor or 'beautiful-ize' the c++ code according to some parameters, such as tab length, {'s position, etc is there anything similar in Ecl
I used to work with eclipse for nearly all the languages I need. I'm asked to work on a tool developed in C# and so, I would like to stay in the same familiar environment. I've found the improve's plu
So far I use to develop in Java. Java is multi-platform (now works on Android!), has a very powerfull VM and is open, well behaved, etc. But is also old and seems to be stopped on time in terms of lan
I've been looking into Compass and the more I look, the more it feels like the way that CSS should be written. As a test case, I'd like to use it in one of my CakePHP projects. Unfortunately, I'm havi
...