User forums > Help

c++11 compilation

(1/3) > >>

saperlipopette:
Hi,
I work with ubuntu 12.04 64bits
I have newly installed g++ 4.7, (the one with C++11 features)
I can compile a simple program on the command line with this pattern:
--- Code: ---g++-4.7 -std=c++11 tst_threads2.cpp -o tst_threads2 -lpthread

--- End code ---

After several tests, I manages to have codeBlock compiling the same way. I used a specific build command as shown in the screen capture below.


The code compiles now  :D
The problem is it does not link.
I get the following message:

Compiling: main2.cpp
Linking console executable: bin/Debug/essai1
g++: fatal error: -fuse-linker-plugin, but liblto_plugin.so not found
compilation terminated.

Please do not expect any basic knowledge on codeBlock from myself. I am totally new to codeBlock.
Actually, I am trying to have C++11 compiling on either codeBlock and Eclipse. I will stick to the first one that will be running.

Thanks for reading,
Olivier

Alpha:
If you are using Code::Blocks 10.05, I would recommend first switching to this PPA.

Just as the red text in your screen shot says ;), this is not the location you want to be modifying settings in.  Switch it back to how it used to be.  Next open Settings->Compiler... find the "Compiler Flags" box (it should be right there) and check the one talking about C++11.  (If you decided to stick with Code::Blocks 10.05, the option will not be there, so add -std=c++11 to the "Other options" tab.)
Switch to the "Toolchain executables" tab and change all g++s to g++-4.7.

saperlipopette:
Alpha,
Many thanks for helping.
I have spent the entire day posting my problem to all the forums I could find on the Internet and you are the first to make me make a step forward.
I still have questions:
* I plugged the PPA and made a sudo apt-get update. The system actually downloaded some stuff from the new PPA but CodeBlock is still the 10.05. What did I miss?
* Thanks to your advices, I succeeded at compiling AND linking my hello world project.
* BUT: This multithread project hangs when starting the thread.
This is the code

--- Code: ---#include <iostream>
#include <thread>

//This function will be called from a thread
void call_from_thread() {
    std::cout << "Hello, from thread!" << std::endl;
}

int main() {
    std::cout << "Hello, from main!" << std::endl;

    //Launch a thread
    std::thread t1(call_from_thread);

    //Join the thread with the main thread
    t1.join();


    return 0;
}

--- End code ---
This is the output

--- Code: ---olivier@LISAH-OBOKERN:~/codeblocks_projects/essai1/bin/Debug$ ./essai1
Hello, from main!
terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted
Aborted (core dumped)

--- End code ---

and this is the output when compiled from the console:

--- Code: ---olivier@LISAH-OBOKERN:~/codeblocks_projects/essai1$ g++-4.7 -std=c++11 main.cpp -o main -lpthread
olivier@LISAH-OBOKERN:~/codeblocks_projects/essai1$ ./main
Hello, from main!
Hello, from thread!
olivier@LISAH-OBOKERN:~/codeblocks_projects/essai1$
--- End code ---

So, I conclude that something is still missing to CodeBlocks to allow multithreading programming. (single-thraded programs work fine, as far as I tested them)

Again, thanks for helping. I am new to CodeBlock, and so happy that some useful help came at last! :)

MortenMacFly:

--- Quote from: saperlipopette on October 30, 2012, 11:27:43 pm ---So, I conclude that something is still missing to CodeBlocks to allow multithreading programming. (single-thraded programs work fine, as far as I tested them)

--- End quote ---
No, not at all. Please understand that Code::Blocks is an IDE that does only what you tell it to do. If you develop applications that crash its not the fault of Code::Blocks. Code::Clocks itself is heavily multi-threaded and is developed using guess what? Right: Code::Blocks.

So - grab yourself a book about thread programming and start reading. This forum is not dedicated to teach programming, its about the development and usage of Code::Blocks, the IDE.

Luckily there are plenty of forums around capturing such questions.

Also, start reading the manual to Code::Bocks itself, because setting up compilation in the single file's properties is absolutely wrong in the first place. You have project/target specific settings to do so.

saperlipopette:
@MortenMacFly

As told in my last post, the same program compiles and runs from the command line (see the results in the last quoted block).
Only CodeBlocks cannot run it, and this is very likely because I missed something in CodeBlock settings, not in my 5-line piece of code that woks elsewhere.

Thanks, Olivier

Navigation

[0] Message Index

[#] Next page

Go to full version