Author Topic: Adding Linker Options To CodeBlocks  (Read 15710 times)

Offline EverydayDiesel

  • Multiple posting newcomer
  • *
  • Posts: 11
Adding Linker Options To CodeBlocks
« on: January 25, 2017, 02:59:31 am »
Hello,

I am trying to get this program working



Code
#include <iostream>
#include <thread>
#include <future>

using namespace std;

void initiazer(std::promise<int> * promObj)
{
    std::cout<<"Inside Thread"<<std::endl;     promObj->set_value(35);
}

int main()
{
    std::promise<int> promiseObj;
    std::future<int> futureObj = promiseObj.get_future();
    std::thread th(initiazer, &promiseObj);
    std::cout<<futureObj.get()<<std::endl;
    th.join();
    return 0;
}




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

Process returned 134

I went to PROJECT --> BUILD OPTIONS  --> [Select project name in top left] -->  Check -std=c++11

then under

LINKER SETTINGS --> OTHER LINKER OPTIONS --> I typed -pthread


Why wont this application compile?

Thanks in advance

Online stahta01

  • Lives here!
  • ****
  • Posts: 7589
    • My Best Post
Re: Adding Linker Options To CodeBlocks
« Reply #1 on: January 25, 2017, 05:30:47 am »
Please read this FAQ http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
And, the rules. http://forums.codeblocks.org/index.php/topic,9996.0.html

And, if you think it is within the rules post at least a full rebuild log in code tags.

Note: I do NOT do C++ threading; but, your error looks more like a run-time message instead of a compiler/linker message.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline yvesdm3000

  • Almost regular
  • **
  • Posts: 225
Re: Adding Linker Options To CodeBlocks
« Reply #2 on: January 25, 2017, 07:24:43 am »
Clang based code completion for Code::Blocks:   http://github.com/yvesdm3000/ClangLib

Offline EverydayDiesel

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Adding Linker Options To CodeBlocks
« Reply #3 on: January 25, 2017, 03:37:24 pm »
http://stackoverflow.com/questions/19463602/compiling-multithread-code-with-g

It's not related to CodeBlocks

Yves

Thank you for the response.  I realize this is not related to code blocks directly but my question is how do I configure codeblocks with these options.

I saw the thread that you posted before I created this thread.

I go to PROJECT --> BUILD OPTIONS --> [Select project name in top left] --> OTHER COMPILER OPTIONS -->
In the box i append one of the following (I have tried all 3 and none work)

Code
-pthread -lpthread -Wl,--no-as-needed

or

Code
-Wl,--no-as-needed

or

Code
-Wl,--no-as-needed -lpthread

Am I typing this in the correct spot?  my g++ is 4.8.4

Thanks to any information you guys can provide
« Last Edit: January 25, 2017, 03:39:27 pm by EverydayDiesel »

Offline EverydayDiesel

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Adding Linker Options To CodeBlocks
« Reply #4 on: January 25, 2017, 09:23:06 pm »
If i bypass codeblocks completely then it works

Code
$ g++ -c main.cpp -pthread -std=c++11 
$ g++ main.o -o main.out -pthread -std=c++11
$ ./main.out
Inside Thread
35


this code will compile in codeblocks but the program will not execute (it gives the original error)




EDIT:
clean your project and it will work

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Adding Linker Options To CodeBlocks
« Reply #5 on: January 25, 2017, 09:33:27 pm »
The options you want to add are linker options, not compiler options, so you need to add them in the linker tab in your settings, not compiler tab.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]